我在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
。