熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Oracle >> 正文

用JSP處理Oracle中CLOB類型的字段

2022-06-13   來源: Oracle 

  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>

  }


From:http://tw.wingwit.com/Article/program/Oracle/201311/16796.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.