关于往Oracle数据库中插入Clob类型数据问题!如何将String类型数据转换成Clob类型?
问题如下一段程序:
public int insertForm() {
String strsql = " ";
String strtime = " ";
try {
Connection conn = db.getConnection();
strtime = db.getCurrentDate( "yyyy-MM-dd HH:mm:ss ");
strsql = "insert into productor(cpmc,bbh,cpgn,lbid,moreinfo)values(?,?,?,?,?) ";//其中cpgn和moreinfo在数据库中是Clob型字段
PreparedStatement pstmt = conn.prepareStatement(strsql);
pstmt.setString(1, form.getCpmc());
pstmt.setString(2, form.getBbh());
oracle.sql.CLOB clob1=oracle.sql.CLOB.createTemporary(conn,false,oracle.sql.CLOB.DURATION_CALL);
clob1.putString(1,form.getContent());//将form.getContent()(其值为String类型)转换成CLOB型插入数据库
pstmt.setClob(3, clob1);
pstmt.setInt(4, Integer.parseInt(form.getCplx()));
oracle.sql.CLOB clob2=oracle.sql.CLOB.createTemporary(conn,false,oracle.sql.CLOB.DURATION_CALL);
clob2.putString(1,form.getXxxx());//将form.getXxxx()(其值为String类型)转换成CLOB型插入数据库
pstmt.setClob(5, clob2);
pstmt.executeUpdate();
conn.commit();
pstmt.close();
db.close();
} catch (Exception e) {
db.rollback();
e.printStackTrace();
return 2;
e.printStackTrace();