Java Reference
In-Depth Information
}else if(menuSelection.equals("ResultSet")){ // added for Chapter 7
displayTableQueryFrame();
}else if(menuSelection.equals("Exit")){
System.exit(0);
}
}
}
class ExceptionListener implements ActionListener{
public void actionPerformed(ActionEvent event){
String exception = event.getActionCommand();
JOptionPane.showMessageDialog(null, exception,
"SQL Error", JOptionPane.ERROR_MESSAGE);
}
}
class CommandListener implements ActionListener{
public void actionPerformed(ActionEvent event){
String SQLCommand = event.getActionCommand();
executeSQLCommand(SQLCommand);
}
}
public static void main(String args[]){
DBManager dbm = new DBManager();
}
}
It now remains to add the necessary JDBC code to run the query, as discussed in the
next section
.
JDBC Code
In the extended version of the
DatabaseUtilities
class in
Listing 7-5
, the method
executeQuery(String SQLQuery)
has been added to return a
Vector
of
Vectors
containing the
row data from the table. The choice of a
Vector
of
Vectors
is driven partly by the inherent flexibility it
offers, and partly to demonstrate an approach that differs slightly from
Listing 7-1
.
The method
getColumnNamesUsingQuery(String SQLCommand)
has also been added. This method returns a