Result Set muze byt otevreny. Problem je v tom, ze commit operace zavre
resultset.
Musite nastavit
statement.setResultSetHoldability(ResultSet.|HOLD_CURSORS_OVER_COMMIT|);
ale i tak bych to prepsal :-) asi takhle
java.sql.Connection con = null;
try
{
con = DriverManager.getConnection("jdbc:as400/ip", "user", "pass");
PreparedStatement psSelect;
/* A ted 3 verze prvni pokud neexistuje v radku Lob, DB2 neumi mazat
radek pres resultset pokud obsahuje blob */
psSelect = con.prepareStatement(
"SELECT id FROM LIB.HTML_TEXT WHERE text_id=?",
|ResultSet.TYPE_SCROLL_INSENSITIVE,||ResultSet.CONCUR_UPDATABLE);
// pisu to z hlavy takze by to mel byt updatable result set|
ResultSet rs = psSelect.executeQuery();
while(rs.next())
{
rs.deleteRow(); // smaze radek na kterem je kurzor
}
/* a zbytek ...
NEBO (2) je tam treba Blob */
psSelect = con.prepareStatement(
"SELECT id FROM LIB.HTML_TEXT WHERE text_id=?"|);
psSelect.|setResultSetHoldability(ResultSet.|HOLD_CURSORS_OVER_COMMIT|);
psDelete = con.prepareStament("DELETE FROM .... WHERE id=?");
||
ResultSet rs = psSelect.executeQuery();
while(rs.next())
{
psDelete.setInt(rs.getInt(1)); // id
psDelete.executeUpdate();
}
// a zbytek ...
/* A NEBO (3) */
psSelect = con.prepareStatement(
"SELECT id FROM LIB.HTML_TEXT WHERE text_id=?",
|ResultSet.TYPE_SCROLL_INSENSITIVE,||ResultSet.CONCUR_UPDATABLE);
// pisu to z hlavy takze by to mel byt updatable result set|
ResultSet rs = psSelect.executeQuery();
if(rs.next())
{
rs.updateString("NAME", "AINSWORTH"); // updates the
// |NAME| column of row 5 to be |AINSWORTH|
rs.updateRow(); // updates the row in the data source
}
else
{
// pujceno z javadoc api
rs.moveToInsertRow(); // moves cursor to the insert row
rs.updateString(1, "AINSWORTH"); // updates the
// first column of the insert row to be |AINSWORTH|
rs.updateInt(2,35); // updates the second column to be |35|
rs.updateBoolean(3, true); // updates the third column to |true|
rs.insertRow();
rs.moveToCurrentRow();
}
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
if(con!=null)
{
try { con.close() } catch(SQLException e0) { e0.printStackTrace();}
}
}
Z toho (3) je asi nejlepsi reseni protoze neposilate zadne dalsi dotazy
a operuje v ramci selectu.
(2) jde pouzit tehdy obsahuje-li radek LOB (BLOB,CLOB)
(1) je vlastne na prd