Java codeString URL = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
Statement stmt;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection(URL, "userName",
"passwd");
stmt = conn.createStatement();
String sql = "select d_image from display_table where autoid=1 for update";
ResultSet rs =stmt.executeQuery(sql);
if (rs.next()) {
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob(1);
File file = new File("D:\\test.png");
//getBinaryOutputStream(); 这个方法已经过期,不知道用哪个替代
OutputStream outStream = blob.getBinaryOutputStream();
InputStream fin = new FileInputStream(file);
byte[] b = new byte[blob.getBufferSize()];
int leng = 0;
while ( (leng = fin.read(b)) != -1) {
outStream.write(b, 0, leng);
}
}
}catch (ClassNotFoundException cnf) {
System.out.println("driver not find:" + cnf);
} catch (SQLException sqle) {
System.out.println("can't connection db:" + sqle);
} catch (Exception e) {
System.out.println("Failed to load JDBC/ODBC driver.");
};