// Get connection
Connection conn = getConnection();
// start test
String lobContent = "WLS JDBC4 test for NClob.";
String insertSql = "INSERT INTO nclob_table VALUES (?, ?)";
PreparedStatement pstmt = conn.prepareStatement(insertSql);
int loopCount = 10;
StringReader sreader = null;
try
{
for (int i = 0; i < loopCount; i++)
{
pstmt.setInt(1, i);
sreader = new StringReader(lobContent + "-" + i);
// Hangs here
pstmt.setNClob(2, sreader);
pstmt.execute();
sreader.close();
System.out.println("inserted a row..." );
}
}
finally
{
if (pstmt != null)
{
pstmt.close();
}
if (conn != null)
{
conn.close();
}
}
}
The hang occurs at this line of code:
pstmt.setNClob(2, sreader);
In order to avoid the hang you can use the following method:
- setNClob(int, Reader, long)
This then works fine when the following is used.
pstmt.setNClob(2, sreader, sreader.toString().length());
No comments:
Post a Comment