1.CLOB字段的插入
一般情况下,clob类型的数据直接insert可能会因为字符过长而出错,所以要用对象形式来插入。
具体示例:
首先,我们需要创建一个含CLOB字段的表:
create table test (id INTEGER, content clob); |
然后插入空值:
String strSql = “INSERT INTO TEST(id,content) values(‘0001’,?) ”;
con.setAutoCommit(false); //conn为Connection对象
//创建并实例化一个CLOB对象
CLOB clob = new CLOB((OracleConnection)con);
clob = oracle.sql.CLOB.createTemporary((OracleConnection)con,true,1);
//对CLOB对象赋值
clob.putString(1,formateSingleQuotes(Content));
OracleConnection OCon = (OracleConnection)con;
OraclePreparedStatement pstmt = (OraclePreparedStatement)OCon.prepareCall(strSql);
pstmt.setCLOB(1,clob);
int i = pstmt.executeUpdate();
pstmt.close();
OCon.commit();
OCon = null;
con = null;
Boolean flag = true;
if(i <=0)
{
flag = false;
}
if (flag == true)
{
out.print( "");
}
else
{
out.print( "");
} |
注意:
一定不要忘记引入包:import oracle.sql.*,oracle.jdbc.driver.*
2.CLOB类型的修改
针对CLOB字段的修改除了SQL语句外其他和插入相同
String strSql = “UPDATE TEST set content=? Where Id=’0001’ ”;
con.setAutoCommit(false); //conn为Connection对象
//创建并实例化一个CLOB对象
CLOB clob = new CLOB((OracleConnection)con);
clob = oracle.sql.CLOB.createTemporary((OracleConnection)con,true,1);
//对CLOB对象赋值
clob.putString(1,formateSingleQuotes(Content));
OracleConnection OCon = (OracleConnection)con;
OraclePreparedStatement pstmt = (OraclePreparedStatement)OCon.prepareCall(strSql);
pstmt.setCLOB(1,clob);
int i = pstmt.executeUpdate();
pstmt.close();
OCon.commit();
OCon = null;
con = null;
Boolean flag = true;
if(i <=0)
{
flag = false;
}
if (flag == true)
{
out.print( "");
}
else
{
out.print( "");
} | |
阅读(255) | 评论(0) | 转发(0) |