ODBC写图片到表中Blob字段
连接oracle ta表中有个Blob字段pic
public static boolean insertTable(byte data[]){//data为图片的流
Connection co=null;
java.sql.PreparedStatement st=null;
boolean bool=false;
try{
co=DB.DBCtl.Connect();
co.setAutoCommit(false);
String sql="insert into ta (id,pic) values (1,empty_blob())";
st=co.prepareStatement(sql);
Log.outPutLog("aaaaaaaaaaaaaaaaa");
st.executeUpdate();
Log.outPutLog("bbbbbbbbbbbbbbbbbbbb");
ResultSet rs = st.executeQuery("select pic from ta for update");
Log.outPutLog("ccccccccc");
if(rs.next())
{
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob(Tables.NewsPic.pic);
BufferedOutputStream out = new BufferedOutputStream(blob.getBinaryOutputStream());
out.write(data);
out.close();
}
co.commit();
}catch(Exception e){Log.outPutLog(e);}
finally{closeConnection(co,st);}
return bool;
}
用jdbc:oracle:thin:连时就可以写入.
用jdbc:odbc连时就报错:
java.sql.SQLException: Driver does not support this function
java.sql.SQLException: [Oracle][ODBC]Invalid transaction state.
日志输出:
aaaaaaaaaaaaaaa
bbbbbbbbbbbbbbb
就没了.
是("select pic from ta for update");这句出错.问要用odbc连数据库如何实现以上代码,把图片写入Blob字段