Class.forName("Oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl", "111", "111");
//處理事務
con.setAutoCommit(false);
Statement st = con.createStatement();
//插入一個空對象
st.executeUpdate("update cc_ac03 set picture=empty_blob() where aac002='"+idcard+"'");
//用for update方式鎖定數據行
ResultSet rs = st.executeQuery(
"select picture from cc_ac03 where aac002='"+idcard+"'");
if (rs.next()) {
//得到java.sql.Blob對象,然後Cast為oracle.sql.BLOB
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob(1);
//到數據庫的輸出流
OutputStream outStream = blob.getBinaryOutputStream();
// ByteArrayInputStream bis=upload.getFiles().getFile(0).getContentStream();
//這裡用一個文件模擬輸入流
// File file = new File(picture);
// InputStream fin = new FileInputStream(file);
// SmartUpload su = new SmartUpload();
//將輸入流寫到輸出流
byte[] b = new byte[blob.getBufferSize()];
int len = 0;
while ( (len = stream.read(b)) != -1) {
outStream.write(b, 0, len);
//blob.putBytes(1,b);
}
//依次關閉(注意順序)
// fin.close();
outStream.flush();
outStream.close();
con.commit();
con.close();
}
解決的心得就是一定要把流文件存入數據庫,而不是存本機的東東,不然就會去讀本機的東西了。其實解決非常簡單,過程卻是痛苦的
ByteArrayInputStream stream = upload.getFiles().getFile(0).getContentStream();這兒就已經得到流文件的值啦
Linux 系統崩潰後(no such file or directory)如何搶救數據庫
Linux格式化分區報錯Could not start /dev/sda No such file or directory 解決辦法
Linux系統入門學習:修復“fatal error: openssl/aes.h: No such file or directory
Linux下修復“fatal error: jsoncpp/json/json.h: No such file or directory”
Linux中VMware啟動報錯:could not open /dev/ vmmon:no such file or directory
Linux下執行.sh文件提示No such file or directory