您的位置:首页 > 数据库 > Oracle

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

2015-01-07 18:46 483 查看
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();

 }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: