JSP连接ORACLE,并操作ORACLE中的CLOB字段(方法一)



JSP连接ORACLE,并操作ORACLE中的CLOB字段(方法一)
分类: Oracle


JSP连接ORACLE,并操作ORACLE中的CLOB字段


1、classpath
  classpath=D:\Win2kProgram\Oracle\Ora81\jdbc\lib\classes12.zip
2、修改ORACLE参数
  修改D:\Win2kProgram\Oracle\admin\DBDEMO\pfile\init.ora中
  "compatible = 8.1.0"为8.1.0以上,否则会出现操作CLOB字段错误的报告。
3、连接ORACLE
  public String ClassString=null;
  public String ConnectionString=null;
  public Connection Conn;
      ClassString="oracle.jdbc.driver.OracleDriver";
      ConnectionString="jdbc:oracle:oci8:User/Psw@Database";
      Class.forName(ClassString);
      Conn = DriverManager.getConnection(ConnectionString);
4、INSERT记录
   表TabTest为演示表,字段otherinfo为CLOB
      String otherinfo;
      String Sql="insert into TabTest (name,sex,otherinfo) values (?,?,?) ";
      prestmt=ObjConnBean.Conn.prepareStatement(Sql);
      prestmt.setString(1, "刘维");
      prestmt.setString(2, "男");
      StringBufferInputStream sbin = new StringBufferInputStream(otherinfo);
      prestmt.setAsciiStream(3,sbin,otherinfo.length());
      ObjConnBean.Conn.setAutoCommit(true);
      prestmt.execute();
      ObjConnBean.Conn.commit();
      prestmt.close();
5、更新
   同INSERT
6、删除
   一般的删除方法就可以
7、查询
      strSql="SELECT * from TabTest Where name='刘维'";
      ResultSet rs=null;
      rs = ObjConnBean.ExecuteQuery(strSql);
      if(rs.next()){
   InputStream instream=rs.getAsciiStream("otherinfo");
   BufferedReader buffer=new BufferedReader(new InputStreamReader(instream));
   String tempstr="";
   String strsum="";
   while ((tempstr=buffer.readLine())!=null)
   {
     strsum=strsum+tempstr;
   }
   buffer.close();
 }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值