//这个适用于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();
}
}
}
}