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

来源:互联网 发布:于莺淘宝店假货 编辑:程序博客网 时间:2024/06/06 02:05


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
原创粉丝点击