`

jdbc 处理大字段blob

    博客分类:
  • jdbc
阅读更多

 

 

public void updateCellModel(String sql, String cellfile, String contain,  String cellXml) {

try {

Connection con = null;

PreparedStatement ps = null;

ResultSet rs = null;

try {

con = getSession().connection();

ps = con.prepareStatement(sql);

rs = ps.executeQuery();

while (rs.next()) {

if(null!=cellfile){

CLOB clob = (CLOB) rs.getClob(1);

BufferedWriter out = new BufferedWriter(clob.getCharacterOutputStream());

BufferedReader in = new BufferedReader(new StringReader(cellfile));

int c;

while ((c = in.read()) != -1) {

out.write(c);

}

out.close();

in.close();

}

if(null!=contain){

CLOB clob1 = (CLOB) rs.getClob(2);

BufferedWriter out1 = new BufferedWriter(clob1.getCharacterOutputStream());

BufferedReader in1 = new BufferedReader(new StringReader(contain));

int c1;

while ((c1 = in1.read()) != -1) {

out1.write(c1);

}

out1.close();

in1.close();

}

if(null!=cellXml){

CLOB clob3 = (CLOB) rs.getClob(3);

BufferedWriter out3 = new BufferedWriter(clob3.getCharacterOutputStream());

BufferedReader in3 = new BufferedReader(new StringReader(cellXml));

int c3;

while ((c3 = in3.read()) != -1) {

out3.write(c3);

}

out3.close();

in3.close();

}

}

} catch (Exception e) {

e.printStackTrace();

throw new BusinessException("执行SQL语句时出错!", e);

}finally{

if(rs != null){

rs.close();

rs = null;

}

if(ps != null){

ps.close();

ps = null;

}

}

} catch (Exception e) {

e.printStackTrace();

throw new BusinessException("保存出错!", e);

}

}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics