import java.io.CharArrayReader;
import java.io.CharArrayWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.Writer;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class InsertClob {
public static void main(String[] args) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection(
"jdbc:oracle:thin:@127.0.0.1:1521:ORCL", "scott", "tiger");
PreparedStatement pstmt = null;
ResultSet rs = null;
String query = "insert into testclob(ID,CONTENT) values(?,empty_clob())";
con.setAutoCommit(false);
pstmt = con.prepareStatement(query);
pstmt.setString(1,"6");
pstmt.executeUpdate();
pstmt = null;
query = "select CONTENT from testclob where id = '6' for update";
pstmt = con.prepareStatement(query);
rs= pstmt.executeQuery();
oracle.sql.CLOB clobtt = null;
if(rs.next()){
clobtt = (oracle.sql.CLOB)rs.getClob(1);
}
Writer wr = clobtt.getCharacterOutputStream();
InputStream is =new FileInputStream("d://1234.txt");
int t =0;
while((t=is.read())!= -1 ){
wr.write(t);
}
wr.flush();
wr.close();
rs.close();
con.commit();
con.close();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
在oracle中查看clob字段的长度
select dbms_lob.getlength(content) from testclob where id =5