请教大家:clob操作问题(附代码)
发现插入文章太长(20k以内)的话就会报io异常,请大家看看错在哪里。环境:Oracle8,weblogic。以下是我的代码:
……
/* 设定不自动提交 */
this.dbConn.setAutoCommit(false);
try
{
String strSql = " Insert into TPolicy(PolicyID,PolicyInfo values(" + policyID + ","EMPTY_CLOB() )";
boolean addok = false;
if (this.dbConn.executeUpdate(strSql) > 0)
{
addok = true;
}
String strSql2 = "SELECT PolicyInfo FROM TPolicy WHERE PolicyID= " +
policyID + " FOR UPDATE";
ResultSet rs = this.dbConn.executeQuery(strSql2);
oracle.sql.CLOB clob = null;
String strsql3 = "";
String infile = "D:/test/TempPolicyIn.txt";
while (rs.next())
{
/* 取出此CLOB对象 */
clob = (oracle.sql.CLOB) rs.getClob("PolicyInfo");
/* 向CLOB对象中写入数据 */
BufferedWriter out = new BufferedWriter(clob.getCharacterOutputStream());
BufferedReader in = new BufferedReader(new FileReader(infile));
int c;
while ( (c = in.read()) != -1) {
out.write(c);
}
in.close();
out.close();
}
/* 正式提交 */
this.dbConn.commit();
if (addok)
{
return policyID;
}
else
{
System.err.println("新增政策失败");
this.errMsg = "新增政策失败!";
return -1;
}
}catch (Exception ex)
{
this.dbConn.rollback();
errMsg = "新增政策异常!";
System.err.println("add ex:"+ex.toString());
return -1;
}