Java Reference
In-Depth Information
try
{
//Step 2…
statement = connection.createStatement();
System.out.println(
"\nInitial contents of table:");
//Steps 3 and 4…
displayTable();
//Start of step 5…
String insert = "INSERT INTO Accounts"
+ " VALUES (123456,'Smith',"
+ "'John James',752.85)";
int result = statement.executeUpdate(insert);
if (result == 0)
System.out.println(
"\nUnable to insert record!");
String change = "UPDATE Accounts"
+ " SET surname = 'Bloggs',"
+ "fi rstNames='Fred Joseph'"
+ " WHERE acctNum = 123456";
result = statement.executeUpdate(change);
if (result == 0)
System.out.println(
"\nUnable to update record!");
String remove = "DELETE FROM Accounts"
+ " WHERE balance < 100";
result = statement.executeUpdate(remove);
if (result == 0)
System.out.println(
"\nUnable to delete record!");
System.out.println(
"\nNew contents of table:");
displayTable();
//End of step 5.
//Step 6…
connection.close();
}
catch(SQLException sqlEx)
{
System.out.println(
"* SQL or connection error! *");
sqlEx.printStackTrace();
System.exit(1);
}
Search WWH ::




Custom Search