H
holmej_99
Guest
I have the code written so far so I can run a java coded program for a cell phone. I can enter numbers, send, redial, clear and end. Now, I am trying to add a contact list from a database. From here I need to select to dial, edit, delete or add. I am familuar with the sql code, but not combining the java code and sql. Right now the only thing I can do is add one item (phone #). Does anyone have any code examples on how to do this?
Below is some of the code I have now:
// This is at the beginning of the code
private final static String sql = "select contactNumber from contactlist where contactID=?";
private final static String dbURL="jdbc
dbc:contactListDB1";
private Connection conn = null;
//here is what is in the main part of the program
public void contactInfo() {
try {
PreparedStatement psmt=conn.prepareStatement(sql);
psmt.setInt(1,Integer.parseInt(contactNumberTextField.getText()));
ResultSet rset=psmt.executeQuery();
if (rset.next()) {
contact= rset.getString("contactNumber");
contactDisplay.setText(contact);
bClear.setEnabled(true);
rset.close();
}
else
JOptionPane.showMessageDialog(this,"Could not find the contact # in the database.");
}
catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this,"Could not find the number # in the database.");
}
catch (SQLException e) {
JOptionPane.showMessageDialog(this,"SQL Error while reading the database.");
}
}
Below is some of the code I have now:
// This is at the beginning of the code
private final static String sql = "select contactNumber from contactlist where contactID=?";
private final static String dbURL="jdbc
private Connection conn = null;
//here is what is in the main part of the program
public void contactInfo() {
try {
PreparedStatement psmt=conn.prepareStatement(sql);
psmt.setInt(1,Integer.parseInt(contactNumberTextField.getText()));
ResultSet rset=psmt.executeQuery();
if (rset.next()) {
contact= rset.getString("contactNumber");
contactDisplay.setText(contact);
bClear.setEnabled(true);
rset.close();
}
else
JOptionPane.showMessageDialog(this,"Could not find the contact # in the database.");
}
catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this,"Could not find the number # in the database.");
}
catch (SQLException e) {
JOptionPane.showMessageDialog(this,"SQL Error while reading the database.");
}
}