public String fileMediaSave(InputStream in,String id,String tablename,String columnname) throws Exception{
//FileInputStream in = new FileInputStream(file);
Statement stmt = null;
BLOB blob = null;
try{
stmt = this.db.getConnection().createStatement();
/*String sql = String.format("insert into T_ER_SRCDAT (ID,ESFID,DATA) values (%1$s,%1$s,empty_blob())",id);
log.info(sql);
stmt.execute(sql);*/
String sql = String.format("update "+ tablename +" set "+ columnname +"=empty_blob() where id='%s'",id);
log.info(sql);
stmt.execute(sql);
ResultSet rset = null;
sql = String.format("SELECT "+ columnname +" FROM " + tablename + " where id='%1$s' FOR UPDATE",id);
log.info(sql);
rset = stmt.executeQuery(sql);
while (rset.next()) {
blob = ((OracleResultSet) rset).getBLOB(1);
}
int chunk = blob.getChunkSize();
System.out.println("chunk size = " + chunk);
OutputStream outstream = blob.getBinaryOutputStream();
byte[] buffer = new byte[chunk];
while (in.read(buffer)!=-1)
{
outstream.write(buffer);
}
outstream.close();
in.close();
stmt.close();
blob = null;
return id;
}
catch(Exception e)
{
if(stmt!=null)
stmt.close();
blob = null;
e.printStackTrace();
return "false";
}
}
写入大数据,以oracl 为例
最新推荐文章于 2024-04-10 17:54:15 发布