public void blobWrite(String tablename, long rowid, byte[] mycontent ){
try{
String newid=java.lang.String.valueOf(rowid);
String content = new String();
//
System.out.println("开始将数据写入到blob列中");
conn.setAutoCommit(false);
//前提是插入成功,id 唯一,且存在 ID字段
String sql2 = "select xm,xp from "+tablename+" where id="+newid+" for update";
System.out.println(sql2);
Statement st = conn.createStatement();
ResultSet rs=st.executeQuery(sql2);
if(rs.next()){
System.out.println(rs.getString("xm"));
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob("xp");
OutputStream outStream = blob.getBinaryOutputStream();
outStream.write(mycontent);
outStream.flush();
outStream.close();
conn.commit();
rs.close();
st.close();
}
}catch(Exception e){
System.out.println(e.getMessage());
}
}
xm打印正常,但是rs.getBlob("xp")一直为空,使用sql2在数据库里运行是正常的,不知道是为什么?请大虾指教!
try{
String newid=java.lang.String.valueOf(rowid);
String content = new String();
//
System.out.println("开始将数据写入到blob列中");
conn.setAutoCommit(false);
//前提是插入成功,id 唯一,且存在 ID字段
String sql2 = "select xm,xp from "+tablename+" where id="+newid+" for update";
System.out.println(sql2);
Statement st = conn.createStatement();
ResultSet rs=st.executeQuery(sql2);
if(rs.next()){
System.out.println(rs.getString("xm"));
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob("xp");
OutputStream outStream = blob.getBinaryOutputStream();
outStream.write(mycontent);
outStream.flush();
outStream.close();
conn.commit();
rs.close();
st.close();
}
}catch(Exception e){
System.out.println(e.getMessage());
}
}
xm打印正常,但是rs.getBlob("xp")一直为空,使用sql2在数据库里运行是正常的,不知道是为什么?请大虾指教!
outStream.write(mycontent);
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob("xp");
InputStream blob_in= blob.getBinaryOutputStream();int tmp;
while((tmp=blob_in.read())!=-1){
file.write(tmp);
}
file.close;
blob_in.close;
connection.close;
outStream.write(mycontent);