少年阿宾

那些青春的岁月

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

//这个适用于oracle10,11,以前oracle9操作CLOB字段相当的繁琐,记着导入驱动包 
package com.abin.wto.dbs.oracle; 

import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 

public class OperateOracle { 
public static void main(String[] args) { 
Connection conn=null; 
PreparedStatement ps=null; 
ResultSet rs=null; 
try { 
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); 
String url="jdbc:oracle:thin:@localhost:1521:XE"; 
conn=DriverManager.getConnection(url,"abin","abin"); 
String sql="insert into bignumber values(?,?)"; 
ps=conn.prepareStatement(sql); 
ps.setInt(1, 1); 
oracle.sql.CLOB clob=oracle.sql.CLOB.createTemporary(conn, false, oracle.sql.CLOB.DURATION_SESSION); 
clob.open(oracle.sql.CLOB.MODE_READWRITE); 
clob.setString(3, "llll"); 
ps.setClob(2, clob); 
int result=ps.executeUpdate(); 
System.out.println("result="+result); 
} catch (Exception e) { 
e.printStackTrace(); 
} 
} 

} 











package com.abin.wto.dbs.oracle;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import oracle.sql.CLOB;

public class OperateOracle {
 public static void main(String[] args) {
  Connection conn=null;
  PreparedStatement ps=null;
  ResultSet rs=null;
  try {
   Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
   String url="jdbc:oracle:thin:@localhost:1521:XE";
   conn=DriverManager.getConnection(url,"abin","abin");
   String sql="insert into bignumber values(?,?)";
   ps=conn.prepareStatement(sql);
   ps.setInt(1, 8888);
   java.sql.Clob  clob=oracle.sql.CLOB.createTemporary(conn, false, oracle.sql.CLOB.DURATION_SESSION);
   clob.setString(1, "55555555555555");
   ps.setClob(2, clob);
   int result=ps.executeUpdate();
   System.out.println("result="+result);
  } catch (Exception e) {
   e.printStackTrace();
  }finally{
   if(ps!=null){
    try {
     ps.close();
    } catch (SQLException e) {
     e.printStackTrace();
    }
   }
   try {
    CLOB.freeTemporary(null);
   } catch (SQLException e) {
    e.printStackTrace();
   }
  }
 }

}

 

posted on 2013-01-08 22:00 abin 阅读(1774) 评论(0)  编辑  收藏 所属分类: oracle

只有注册用户登录后才能发表评论。


网站导航: