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( "<script>alert('成功保存!'); </script>");
}
else
{
out.print( "<script>alert('保存数据时出错,请检查你输入的数据格式是否符合要求');self.history.back ();</script>");
}
注意:
一定不要忘记引入包: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( "<script>alert('成功保存!'); </script>");
}
else
{
out.print( "<script>alert('保存数据时出错,请检查你输入的数据格式是否符合要求');self.history.back ();</script>");
}
新闻热点
疑难解答