skcchan
asked on
How to insert CLOB from a Java program via JDBC
Please help. Whenever I insert a clob > 4k, I get an error message listed below:
-----
Oracle 9i (Release 2)
Java 1.4.1
-----
CREATE TABLE mytab (c CLOB);
-----
String s = a_very_long_string_30k_byt es;
Reader reader = new StringReader(s);
PreparedStatement pstmt = conn.prepareStatement
("INSERT INTO mytab (c) VALUES (?)");
pstmt.setCharacterStream(1 ,reader,s. length());
pstmt.execute();
pstmt.close();
conn.close();
-----
Error Messages:
Io exception: Connection reset
java.sql.SQLException: Io exception: Broken pipe
at oracle.jdbc.dbaccess.DBErr or.throwSq lException (DBError.j ava:134)
at oracle.jdbc.dbaccess.DBErr or.throwSq lException (DBError.j ava:179)
at oracle.jdbc.dbaccess.DBErr or.throwSq lException (DBError.j ava:333)
at oracle.jdbc.driver.OracleS tatement.c lose(Oracl eStatement .java:648)
at oracle.jdbc.driver.OracleP reparedSta tement.pri vateClose( OraclePrep aredStatem ent.java:4 85)
at oracle.jdbc.driver.OracleP reparedSta tement.clo se(OracleP reparedSta tement.jav a:393)
at com.rawmart.itools.Import. main(Impor t.java:168 )
-----
Oracle 9i (Release 2)
Java 1.4.1
-----
CREATE TABLE mytab (c CLOB);
-----
String s = a_very_long_string_30k_byt
Reader reader = new StringReader(s);
PreparedStatement pstmt = conn.prepareStatement
("INSERT INTO mytab (c) VALUES (?)");
pstmt.setCharacterStream(1
pstmt.execute();
pstmt.close();
conn.close();
-----
Error Messages:
Io exception: Connection reset
java.sql.SQLException: Io exception: Broken pipe
at oracle.jdbc.dbaccess.DBErr
at oracle.jdbc.dbaccess.DBErr
at oracle.jdbc.dbaccess.DBErr
at oracle.jdbc.driver.OracleS
at oracle.jdbc.driver.OracleP
at oracle.jdbc.driver.OracleP
at com.rawmart.itools.Import.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
checkout http://orafaq.net/msgboard/java/messages/1290.htm that gives you a nice example!
Cheers, Stefan
Cheers, Stefan
ASKER
At last, I found out why my code does not work. Oracle said that if you want to use PreparedStatment.setCharac terStream for a LOB > 4k, you must use JDBC OCI driver. In other words, JDBC thin layer (type IV) does not work for any LOB that larger than 4k bytes when using pstmt.setCharacterStream.
BTW, thanks a lot for your comments.
skc
BTW, thanks a lot for your comments.
skc
skc,
then ypwitkow in the first post was right, that was what he exactly told you.
... and in my link to http://orafaq.net/msgboard/java/messages/1290.htm you could find the workarround and an example using the oracle java classes.
please close the thread ..
Cheers,
Stefan
then ypwitkow in the first post was right, that was what he exactly told you.
... and in my link to http://orafaq.net/msgboard/java/messages/1290.htm you could find the workarround and an example using the oracle java classes.
please close the thread ..
Cheers,
Stefan
ASKER
OraclePreparedStatement and oracle.sql.CLOB bu it does not help.
Can anyone give me an example that insert a CLOB without SELECT. Thanks
SKC