cbuf[randomOffset] = 'e';
for (int i = 0; i < 10; i++) {
ps.setInt(1, i);
ps.setString(2, "mname" + i);
ps.setInt(3, 0);
ps.setCharacterStream(4, new CharArrayReader(cbuf), len);
ps.setAsciiStream(5, new ByteArrayInputStream(buf), len);
rowCount += ps.executeUpdate();
}
commit();
println("Rows inserted =" + rowCount);
try {
ps.setInt(1, 11);
rowCount += ps.executeUpdate();
} catch (SQLException sqle) {
if (usingDerbyNetClient()) {
// DERBY-4315. This SQLState is wrong for client.
// It should have the same behavior as embedded.
// That may rquire some additional work in addition
// to DERBY-4315.
// Remove special case when DERBY-4315
// is fixed or at least throw XJ001 and
// avoid bad data insert.
assertSQLState("XN017", sqle);
// rollback the bad insert.
rollback();
} else {
println("UNEXPECTED EXCEPTION - streams cannot be "
+ "re-used but in case of varchar, stream is materialized the"
+ " first time around. So multiple executions using streams should "
+ " work fine. ");
throw sqle;
}
}
PreparedStatement pss = prepareStatement(" select lvc,vc from test500_verify where "
+ "id = ?");
verifyDerby500Test(pss, buf, cbuf, 0, 10, false);
// do the update, update must qualify more than 1 row and update will
// pass for char,varchar,long varchar columns.
PreparedStatement psu = prepareStatement("update test500_verify set vc = ? "
+ ", lvc = ? where mvalue = ? ");
buf[randomOffset + 1] = (byte) 'u';
cbuf[randomOffset + 1] = 'u';
rowCount = 0;
psu.setAsciiStream(1, new ByteArrayInputStream(buf), len);
psu.setCharacterStream(2, new CharArrayReader(cbuf), len);
psu.setInt(3, 0);
rowCount += psu.executeUpdate();
println("DERBY500 for varchar #1 Rows updated =" + rowCount);