⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 0202.htm

📁 精通struts源码,孙卫琴.经过更新后的,请查收,
💻 HTM
字号:
<html>

<head>
<title>新时代软件教程:操作系统 主页制作 服务器 设计软件 网络技术 编程语言 文字编辑</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
<!--
body, table {font-size: 9pt; font-family: 宋体}
a {text-decoration:none}
a:hover {color: red;text-decoration:underline}
.1  {background-color: rgb(245,245,245)}
-->
</style>
</head>
<p align="center"><script src="../../1.js"></script></a>
<p align="center"><big><strong>图片的数据库存储</strong></big></p>
<div align="right">---摘自互联网</div>

<br>import&nbsp; java.io.*;&nbsp; <br>
import&nbsp; java.sql.*;&nbsp; <br>
public&nbsp; class&nbsp; InsertBlob&nbsp; {&nbsp; <br>
public&nbsp; static&nbsp; void&nbsp; main(String&nbsp; args[])&nbsp; {&nbsp; <br>
<br>
String&nbsp; username;&nbsp; <br>
String&nbsp; password;&nbsp; <br>
String&nbsp; url;&nbsp; <br>
String&nbsp; dropString;&nbsp; <br>
String&nbsp; createString;&nbsp; <br>
<br>
username&nbsp; =&nbsp; "system";&nbsp; <br>
<br>
password&nbsp; =&nbsp; "manager";&nbsp; <br>
<br>
//&nbsp; The&nbsp; URL&nbsp; that&nbsp; will&nbsp; connect&nbsp; to&nbsp; TECFA's&nbsp; MySQL&nbsp; server&nbsp; <br>
//&nbsp; Syntax:&nbsp; jdbc:TYPEachineort/DB_NAME&nbsp; <br>
url&nbsp; =&nbsp; "jdbcracle:thin:@cs05:1521s05";&nbsp; <br>
//&nbsp; ----&nbsp; configure&nbsp; END&nbsp; <br>
<br>
//&nbsp; INSTALL/load&nbsp; the&nbsp; Driver&nbsp; (Vendor&nbsp; specific&nbsp; Code)&nbsp; <br>
try&nbsp; {&nbsp; <br>
Class.forName("oracle.jdbc.driver.OracleDriver");&nbsp; <br>
}&nbsp; catch(java.lang.ClassNotFoundException&nbsp; e)&nbsp; {&nbsp; <br>
System.err.print("ClassNotFoundException:&nbsp; ");&nbsp; <br>
System.err.println(e.getMessage());&nbsp; <br>
}&nbsp; <br>
<br>
try&nbsp; {&nbsp; <br>
Connection&nbsp; con;&nbsp; <br>
Statement&nbsp; stmt;&nbsp; <br>
<br>
//&nbsp; Establish&nbsp; Connection&nbsp; to&nbsp; the&nbsp; database&nbsp; at&nbsp; URL&nbsp; with&nbsp; usename&nbsp; and&nbsp; password&nbsp; <br>
con&nbsp; =&nbsp; DriverManager.getConnection(url,&nbsp; username,&nbsp; password);&nbsp; <br>
System.out.println&nbsp; ("Ok,&nbsp; connection&nbsp; to&nbsp; the&nbsp; DB&nbsp; worked.&nbsp; Let's&nbsp; see&nbsp; if&nbsp; we&nbsp; can&nbsp; insert&nbsp; something:");&nbsp; <br>
<br>
//&nbsp; con.setAutoCommit(false);&nbsp; <br>
<br>
FileInputStream&nbsp; fis=null;&nbsp; <br>
File&nbsp; file&nbsp; =&nbsp; new&nbsp; File("z.jpg");&nbsp; <br>
try{&nbsp; <br>
fis&nbsp; =&nbsp; new&nbsp; FileInputStream(file);&nbsp; <br>
}&nbsp; catch(FileNotFoundException&nbsp; e)&nbsp; {}&nbsp; <br>
PreparedStatement&nbsp; ps&nbsp; =&nbsp; con.prepareStatement("insert&nbsp; into&nbsp; binary_data&nbsp; values&nbsp; (?,?,?,?,?,?)");&nbsp; <br>
ps.setInt(1,1);&nbsp; <br>
ps.setString(2,"樱花");&nbsp; <br>
ps.setBinaryStream(3,fis,3098);&nbsp; <br>
ps.setString(4,"z.jpg");&nbsp; <br>
ps.setString(5,"3098");&nbsp; <br>
ps.setString(6,"jpg");&nbsp; <br>
ps.executeUpdate();&nbsp; <br>
ps.close();&nbsp; <br>
try{&nbsp; <br>
fis.close();&nbsp; <br>
}&nbsp; catch(IOException&nbsp; e)&nbsp; {}&nbsp; <br>
<br>
System.out.println&nbsp; ("Image&nbsp; Items&nbsp; have&nbsp; been&nbsp; inserted,&nbsp; you&nbsp; can&nbsp; now&nbsp; run&nbsp; the&nbsp; QueryCoffees&nbsp; program");&nbsp; <br>
//&nbsp; Close&nbsp; resources&nbsp; <br>
//&nbsp; stmt.close();&nbsp; <br>
con.close();&nbsp; <br>
}&nbsp; <br>
//&nbsp; print&nbsp; out&nbsp; decent&nbsp; erreur&nbsp; messages&nbsp; <br>
catch(SQLException&nbsp; ex)&nbsp; {&nbsp; <br>
System.err.println("==>&nbsp; SQLException:&nbsp; ");&nbsp; <br>
while&nbsp; (ex&nbsp; !=&nbsp; null)&nbsp; {&nbsp; <br>
System.out.println("Message:&nbsp; "&nbsp; +&nbsp; ex.getMessage&nbsp; ());&nbsp; <br>
System.out.println("SQLState:&nbsp; "&nbsp; +&nbsp; ex.getSQLState&nbsp; ());&nbsp; <br>
System.out.println("ErrorCode:&nbsp; "&nbsp; +&nbsp; ex.getErrorCode&nbsp; ());&nbsp; <br>
ex&nbsp; =&nbsp; ex.getNextException();&nbsp; <br>
System.out.println("");&nbsp; <br>
}&nbsp; <br>
}&nbsp; <br>
<br>
}&nbsp; <br>
}&nbsp; <br>


  </table>
<p align="center"><script src="../../2.js"></script></a>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -