sqlStr = "select table_name from user_tables where table_name='JPGTEST'";
if(!sqlBean.hasResult(conn, sqlStr))
{
displayMessage = (stmt.executeUpdate("create table JPGTEST (fname varchar2(600), bx blob)") == 0) ? "table created successfuly" : "table created failure";
System.out.println(displayMessage);
}
File file = new File("C:\\25.jpg");
fileName = file.getName();
FileInputStream inStream = new FileInputStream(file);//创建输入流,将外部文件输入到InputStream 中。
byte[] buffer = new byte[inStream.available()];
sqlStr = "INSERT INTO JPGTEST VALUES ('" + fileName + "', empty_blob())";
stmt.execute(sqlStr);
ResultSet rs = stmt.executeQuery("select bx from JPGTEST where fname='" + fileName + "' for update");
if(rs.next())
{
BLOB blob = ((OracleResultSet)rs).getBLOB("bx");
OutputStream outStream = blob.getBinaryOutputStream();
inStream.read(buffer);
outStream.write(buffer);
outStream.flush();
stmt.execute("commit");
outStream.close();
System.out.println("文件成功写入数据库");
}
inStream.close();
rs.close();