Baically, this is a small piece my code to allow the user to search the database called "Artists", for records via name. How would i display the information retrieved into a JTable?
private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");/* loads the jdbcodbc driver not using username and password */
Connection connect = DriverManager.getConnection("jdbc:odbc:artist");
Statement state = connect.createStatement();/* Gets a statement */
String query = "SELECT * FROM Artists "+ "WHERE Name = '" + txtName.getText() + "'";
ResultSet results = state.executeQuery(query);/* Result set returned for a query */
if (!results.next()) {
System.out.println("Name is incorrect");
throw new WrongNameException();/* Exception thron if information is incorrect*/
} else {
System.out.println("You have successfully Searched!");
}
state.close();
} catch(SQLException | ClassNotFoundException | WrongNameException e) { /* catches the exceptions */
JOptionPane.showMessageDialog(null,e,"Error ",0);
}
}