これは、私が見つけたいくつかのコードで、あなたが望むことをすると思います:
次のような静的メソッドがあります。
public class DBUtil {
public static CLOB getCLOB(String innStr, Connection conn) throws SQLException,
IOException {
CLOB tempClob = null;
// If the temporary CLOB has not yet been created, create new
tempClob = CLOB.createTemporary(conn, true, CLOB.DURATION_SESSION);
// Open the temporary CLOB in readwrite mode to enable writing
tempClob.open(CLOB.MODE_READWRITE);
// Get the output stream to write
Writer tempClobWriter = tempClob.getCharacterOutputStream();
// Write the data into the temporary CLOB
tempClobWriter.write(innStr);
// Flush and close the stream
tempClobWriter.flush();
tempClobWriter.close();
// Close the temporary CLOB
tempClob.close();
return tempClob;
}
}
そして、次のように使用できます。
CLOB tempClob = DBUtil.getCLOB(longString, connection);
pstmt.setCLOB(colnumber, tempClob);
これには、Clob コンテンツ全体を文字列にする必要があるため、すべてがメモリに読み込まれます。おそらくあなたには適していませんが、私の単純なニーズには合っています。
編集: plsql プロシージャ コールでこのコードを使用したことに注意してください。SQLで直接テストしていません