直接很长的字符串插入到clob字段中会报字符过长的异常,相信大家都会碰到这种情况
String sql = "insert into table(request_id,table_name,total_number,search_result,create_time,flag) values (?,?,?,?,to_date(?,'yyyy-MM-dd HH24:mi:ss'),?)";
Connection dbcon = DB.getInstance().getConnection();
dbcon = dbutils.db.getConnection();
// dbcon.setAutoCommit(false);
CLOB clob = new CLOB((OracleConnection)dbcon);
clob = oracle.sql.CLOB.createTemporary((OracleConnection)dbcon,true,1);
clob.setString(1,search_result);
OracleConnection OCon = (OracleConnection)dbcon;
OraclePreparedStatement ps = (OraclePreparedStatement)OCon.prepareCall(sql);
ps.setString(1, request_id);
ps.setString(2, table_name);
ps.setInt(3, total_number);
ps.setClob(4,clob);
ps.setString(5,sdf.format(new Date()));
ps.setInt(6, flag);
ps.executeUpdate();
ps.close();
ps = null;
// OCon.commit();
// dbcon.setAutoCommit(true);
要单独用到oracle自己的OracleConnection 这个抽象连接类,并且用到它的预处理语句而不是java.sql.*!