在Java 1.4 oracle 10g中转换字符串为Clob



我在Java代码中尝试将字符串转换为Clob时面临问题。我使用java 1.4和oracle 10g.

stmt = conn.prepareStatement("INSERT INTO RAWDATA_EQUIFAX (REQ_ID, BUREAU_CODE, RAWDATA, RESP_TIME) VALUES (?, ?, ?, ?)");
stmt.setClob(3, rawData); //rawData is String in java
我得到的错误是:
The method setClob(int, Clob) in the type PreparedStatement is not applicable for the arguments (int, String)

您应该能够使用PreparedStatement#setCharacterStream(int, Reader, int)

Reader reader = new StringReader(rawData);
stmt.setCharacterStream(3, reader, rawData.length()); //or whicehver index

升级到java 7

对于10g,您不再需要Java端上的clob。只需将连接属性SetBigStringTryClob设置为true,并在JDBC API中使用Strings

http://rocksolutions.wordpress.com/2010/06/07/handling-clobs-made-easy-with-oracle-jdbc-10g/

最新更新