BufferedReader in =
new BufferedReader(new InputStreamReader(System.in));
int rows = 0;
ResultSet rslt = null;
Statement stmt = null;
String sql =
"select code, " +
" description, " +
" inactive_date " +
"from PERSON_IDENTIFIER_TYPE";
// can't use for update clause because of driver defect";
try {
conn.setAutoCommit(false);
stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rslt = stmt.executeQuery(sql);
System.out.println("type = " +
formatType(stmt.getResultSetType()));
System.out.println("concurrency = " +
formatConcurrency(stmt.getResultSetConcurrency()));
while (rslt.next()) {
rows++;
if (rslt.getString(1).equals("SDL")) {
rslt.deleteRow();
System.out.print("Deleted, press Enter to continue...");
System.out.println("");
in.readLine();
}
}
rslt.moveToInsertRow();
rslt.updateString(1, "SDL");
rslt.updateString(2, "State Drivers License");
rslt.updateNull(3);
rslt.insertRow();
rslt.moveToCurrentRow();
System.out.print("Inserted, press Enter to continue...");
System.out.println("");
in.readLine();
stmt.close();
stmt = null;
rslt.close();
rslt = null;
}
catch (SQLException e) {
System.err.println(e.getMessage());
}
finally {
if (rslt != null)
try { rslt.close(); } catch (SQLException ignore) { }
if (stmt != null)
try { stmt.close(); } catch (SQLException ignore) { }
}
try {
stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rslt = stmt.executeQuery(sql);
while (rslt.next()) {
rows++;
if (rslt.getString(1).equals("SDL")) {
rslt.updateString(2, "State Driver's License");
rslt.updateRow();
System.out.print("Updated, press Enter to continue...");
System.out.println("");
in.readLine();
}
}
conn.commit();
System.out.print("Committed, press Enter to continue...");
System.out.println("");
in.readLine();
stmt.close();
stmt = null;
rslt.close();
rslt = null;
}
catch (SQLException e) {
System.err.println(e.getMessage());
}
finally {
if (rslt != null)
try { rslt.close(); } catch (SQLException ignore) { }
if (stmt != null)
try { stmt.close(); } catch (SQLException ignore) { }
}