oracle写入zip包,写入ZIP压缩文件与XML 文件到oracle数据库

public boolean addFileContent(final DocTransfer docTransfer, String enconding, boolean isBom, String fileName) {

boolean bool = false; StringBuffer updateXmlSqlStr = new StringBuffer();

// DOC_TRANSFER_BACKUP DOC_TRANSFER

String sql2 = updateXmlSqlStr.append("insert into ").append(" EDI.DOC_TRANSFER(").append(" FILE_TRANS_ID , BUSINESS_ID,MESSAGE_ID,FUNCTION_CODE,MESSAGE_TYPE,REPRESENTATIVE_PERSON_NAME,")

.append(" SENDER_CODE,RECEIVER_CODE,TRANS_FILE_NAME,SEND_STATUS,SEND_USER,SEND_TIME,OLD_VERSION_FILE_NAME,SGN_COMPANY,TRANS_FILE_CONTENT ) ")

.append(" values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,empty_Blob()) ").toString();

processUpdateWithoutBatch(sql2, new PreparedStatementSetter() {

public void setValues(PreparedStatement ps) throws SQLException {

long currentTime = System.currentTimeMillis();

if (docTransfer.getSendTime() != null) {

currentTime = docTransfer.getSendTime().getTime();

}

ps.setLong(1, docTransfer.getFileTransId().longValue());

// System.out.println("numbrId="+docTransfer.getBusinessId());

ps.setLong(2, docTransfer.getFileTransId().longValue());

ps.setString(3, docTransfer.getMessageId());

ps.setString(4, docTransfer.getFunctionCode());

ps.setString(5, docTransfer.getMessageType());

ps.setString(6, docTransfer.getRepresentativePersonName());

ps.setString(7, docTransfer.getSenderCode());

ps.setString(8, docTransfer.getReceiverCode());

ps.setString(9, docTransfer.getTransFileName());

ps.setString(10, docTransfer.getSendStatus());

ps.setString(11, docTransfer.getSendUser());// SGN_COMPANY

ps.setTimestamp(12, new Timestamp(currentTime));

ps.setString(13, docTransfer.getOldVersionFileName());

ps.setString(14, docTransfer.getSgnCompany());

}

});

updateXmlSqlStr.setLength(0);

updateXmlSqlStr.append("select TRANS_FILE_CONTENT ").append("from EDI.DOC_TRANSFER ").append(" where FILE_TRANS_ID=?").append(" for update");

final java.sql.Blob blob = (java.sql.Blob) processQuery(updateXmlSqlStr.toString(), new PreparedStatementSetter() {

public void setValues(PreparedStatement ps) throws SQLException {

System.out.println("numbrId=" + docTransfer.getFileTransId());

ps.setLong(1, docTransfer.getFileTransId().longValue());

}

}, new ResultSetCallBacker() {

public Object extractData(ResultSet rs) throws SQLException {

java.sql.Blob blob = null;

if (rs.next()) {

blob = rs.getBlob(1);// rs.getClob(1);

// log.info("CLob==="+String.valueOf(clob));

}

return blob;

}

});

try {

OutputStream out = (OutputStream) MethodUtils.invokeMethod(blob, "getBinaryOutputStream", null);

BufferedWriter writer = null;

File file = new File(fileName);

InputStream fin = new FileInputStream(file);

if (docTransfer.getTransFileName().endsWith(".ZIP")) {

// 将输入流写到输出流

byte[] buffer = new byte[1024];

int len = 0;

while ((len = fin.read(buffer)) != -1) {

out.write(buffer, 0, len);

out.flush();

}

// 依次关闭(注意顺序)

fin.close();

out.close();

} else if(docTransfer.getTransFileName().endsWith(".xml")||docTransfer.getTransFileName().endsWith(".XML")){

//String S = new String (docTransfer.getTransFileContent().getBytes("UTF-8"));

BufferedReader br = new BufferedReader(new InputStreamReader(fin,"UTF-8"));

String data = null;

while ((data = br.readLine()) != null) {

//System.out.println(data);

out.write(data.getBytes("UTF-8"));

out.flush();

}

br.close();

out.close();

fin.close();

}else{

if(!ManifestDeclConstats.DOC_CONTENT_ENCODING_UTF_8.equals(StringHelp.toUpperString(StringHelp.trimNull(enconding)))){

if(isBom==true){

final byte[] bom = new byte[] { (byte)0xEF, (byte)0xBB, (byte)0xBF };

out.write(bom);

}

writer = new BufferedWriter(new OutputStreamWriter(out,"GBK"));

}else{

if(isBom==true){

final byte[] bom = new byte[] { (byte)0xEF, (byte)0xBB, (byte)0xBF };

out.write(bom);

}

writer = new BufferedWriter(new OutputStreamWriter(out,ManifestDeclConstats.DOC_CONTENT_ENCODING_UTF_8));

}

writer.write(docTransfer.getTransFileContent());

fin.close();

writer.close();

out.close();

}

} catch (Exception e) {

log.info("获取数据错误");

bool = false;

return bool;

// throw new RuntimeException(e);

}

updateXmlSqlStr.setLength(0);

updateXmlSqlStr.append("update ").append("EDI.DOC_TRANSFER set TRANS_FILE_CONTENT =? where FILE_TRANS_ID=?").toString();

processUpdateWithoutBatch(updateXmlSqlStr.toString(), new PreparedStatementSetter() {

public void setValues(PreparedStatement ps) throws SQLException {

// ps.setClob(1, clob);

ps.setBlob(1, blob);

// ps.setString(2, mftSendRecords.getTransFileContent());

ps.setLong(2, docTransfer.getFileTransId().longValue());

}

});

return true;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值