CLOB字段的插入
一般情况下clob类型的数据直接insert可能会因为字符过长而出错所以要用对象形式来插入
具体示例
首先我们需要创建一个含CLOB字段的表
create table test (id INTEGER content clob)
然后插入空值
String strSql = INSERT INTO TEST(idcontent) values(?)
consetAutoCommit(false) //conn为Connection对象
//创建并实例化一个CLOB对象
CLOB clob = new CLOB((OracleConnection)con)
clob = oraclesqlCLOBcreateTemporary((OracleConnection)contrue)
//对CLOB对象赋值
clobputString(formateSingleQuotes(Content))
OracleConnection OCon = (OracleConnection)con
OraclePreparedStatement pstmt = (OraclePreparedStatement)OConprepareCall(strSql)
pstmtsetCLOB(clob)
int i = pstmtexecuteUpdate()
pstmtclose()
mit()
OCon = null
con = null
Boolean flag = true
if(i <=)
{
flag = false
}
if (flag == true)
{
outprint( <script>alert(成功保存!) </script>)
}
else
{
outprint( <script>alert(保存数据时出错请检查你输入的数据格式是否符合要
求)selfhistoryback ()</script>)
}
注意
一定不要忘记引入包import oraclesql*oraclejdbcdriver*
CLOB类型的修改
针对CLOB字段的修改除了SQL语句外其他和插入相同
String strSql = UPDATE TEST set content=? Where Id=
consetAutoCommit(false) //conn为Connection对象
//创建并实例化一个CLOB对象
CLOB clob = new CLOB((OracleConnection)con)
clob = oraclesqlCLOBcreateTemporary((OracleConnection)contrue)
//对CLOB对象赋值
clobputString(formateSingleQuotes(Content))
OracleConnection OCon = (OracleConnection)con
OraclePreparedStatement pstmt = (OraclePreparedStatement)OConprepareCall(strSql)
pstmtsetCLOB(clob)
int i = pstmtexecuteUpdate()
pstmtclose()
mit()
OCon = null
con = null
Boolean flag = true
if(i <=)
{
flag = false
}
if (flag == true)
{
outprint( <script>alert(成功保存!) </script>)
}
else
{
outprint( <script>alert
(保存数据时出错请检查你输入的数据格式是否符合要求)
selfhistoryback ()</script>)
}