搜索
您的当前位置:首页blob操作

blob操作

来源:智榕旅游
1、存放Blob StringBuffer insertSql = null;

Connection conn = getConnection(); PreparedStatement ps = null; //关闭自动提交 try { conn.setAutoCommit(false); } catch (SQLException e2) { e2.printStackTrace(); return false; } //写入数据 for(WSDToContractFile wsdToContractFile : wsdToContractFileList){ insertSql = new StringBuffer(\"insert into

WSD_TO_CONTRACTFILE(id,CONTRACTID,P_FILESIZE,P_FILE,AGENT_ID,ExchangeSign,ExchangeType) values(\"); insertSql.append(wsdToContractFile.getId()+\); insertSql.append(wsdToContractFile.getContractId()+\); insertSql.append(wsdToContractFile.getPFileSize()+\); insertSql.append(\"empty_blob(),\"); insertSql.append(\"'\"+wsdToContractFile.getAgentId()+\"',\"); insertSql.append(\"'\"+wsdToContractFile.getExchangeSign()+\"',\"); insertSql.append(\"'\"+wsdToContractFile.getExchangeType()+\"'\"); insertSql.append(\")\"); try { ps = conn.prepareStatement(insertSql.toString()); ps.executeUpdate(); //锁定数据行进行更新,注意“for update”语句 ResultSet rs = ps.executeQuery(\"select P_FILE from WSD_TO_CONTRACTFILE where ID='\"+wsdToContractFile.getId()+\"' for update\"); if (rs.next()){ //得到java.sql.Blob对象后强制转换为oracle.sql.BLOB oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob(\"P_FILE\"); OutputStream outStream = blob.getBinaryOutputStream(); byte[] c = wsdToContractFile.getPFile().getBytes(); outStream.write(c, 0, c.length); outStream.flush(); outStream.close(); } } catch (SQLException e1) {

e1.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } }

//关闭连接 try { conn.commit(); ps.close(); conn.close();

} catch (SQLException e) { e.printStackTrace(); return false; }

return true;

因篇幅问题不能全部显示,请点此查看更多更全内容

Top