Java Reference
In-Depth Information
//Finally, the deletion…
results.absolute(3); //Move to row 3.
results.deleteRow();
System.out.println(
"\nNew contents of table:\n");
displayTable();
//End of step 5.
//Step 6…
connection.close();
}
catch(SQLException sqlEx)
{
System.out.println(
"* SQL or connection error! *");
sqlEx.printStackTrace();
System.exit(1);
}
}
public static void displayTable() throws SQLException
{
String select = "SELECT * FROM Accounts";
results = statement.executeQuery(select);
System.out.println();
while (results.next())
{
System.out.println("Account no. "
+ results.getInt(1));
System.out.println("Account holder: "
+ results.getString(3)
+ " "
+ results.getString(2));
System.out.printf("Balance: %.2f %n%n",
results.getFloat(4));
}
}
}
The output from this program is shown in Fig. 7.6 .
Search WWH ::




Custom Search