我的oracle数据表名sst_y_news,字段为:id:number,name:varchar2(40),content blob
我的第一个页addnew.jsp面中有两个输入框:name和content,其中name的输入框为text类型,而content为textarea
现在addnewscheck.jsp中获取到了content里面的数据,我想把content的数据插入到sst_y_news表中的content字段中,其中content字段为blob类型,请问该如何写代码,谢谢
我的第一个页addnew.jsp面中有两个输入框:name和content,其中name的输入框为text类型,而content为textarea
现在addnewscheck.jsp中获取到了content里面的数据,我想把content的数据插入到sst_y_news表中的content字段中,其中content字段为blob类型,请问该如何写代码,谢谢
public int insertInfo() throws SQLException, IOException
{
int result = 0;
connection = this.getConnection();
// connection.setAutoCommit(false);
Statement stmt = connection.createStatement();
stmt.executeUpdate("insert into txjblob values(2,EMPTY_BLOB())");
ResultSet rs = stmt.executeQuery("SELECT b FROM txjblob WHERE x=2 FOR UPDATE NOWAIT"); FileInputStream fin;
fin = new FileInputStream("D:\\bcarq.gif");
byte[] blobBuf = new byte[(int)fin.available()];
fin.read(blobBuf);
fin.close(); if(rs.next())
{
System.out.println(blobBuf.length);
BLOB blob = (oracle.sql.BLOB)rs.getBlob(1);
OutputStream out = blob.getBinaryOutputStream();
out.write(blobBuf);
out.close();
connection.commit();
}
stmt.close();
// connection.setAutoCommit(true);
this.closeConnection();
return result;
}