JDBC Questions
i dont know sql too well and this is why im having a problem at the moment. ive been posting a lot lately with different questions and u guys have really helped me out. but i thought that this time id post a few questions in 1 post :)
1) i want to be able to update a contact from a certain table (e.g. table "A" if the contacts name starts with an A). this is my updateContact method:
publicvoid updateContact(ContactPanel updatePanel){
try{
preparedStatement = connection.prepareStatement("update A set NAME = ?, NUMBER = ?, EMAIL = ? where ID = ?");
preparedStatement.setString(1, updatePanel.getName());
preparedStatement.setString(2, updatePanel.getNumber());
preparedStatement.setString(3, updatePanel.getEMail());
preparedStatement.executeUpdate();
}catch(SQLException ex){
ex.printStackTrace();
}
}
first of all this will only work on table A, but i have tables from A-Z. so instead of"update A set NAME = ?, NUMBER = ?, EMAIL = ? where ID = ?"
what would i need to put instead of A? i thought i could maybe do this:"update " + updatePanel.getName().toUpperCase().charAt(0) +" set NAME = ?, NUMBER = ?, EMAIL = ? where ID = ?"
also, u probably noticed that i have 4 ?s and only 3 setters. i have made an identity column in each table called "ID". is there a setter for this?
2) almost like the 1st question but this time i want to be able to delete a certain contact. this is my deleteContact method:
publicvoid deleteContact(String contactName, String contactNumber, String contactEMail){
try{
preparedStatement = connection.prepareStatement("delete from A where NAME = ? and NUMBER = ? and EMAIL = ?");
preparedStatement.setString(1, contactName);
preparedStatement.setString(2, contactNumber);
preparedStatement.setString(3, contactEMail);
preparedStatement.executeUpdate();
}catch(SQLException ex){
ex.printStackTrace();
}
}
can i put an * instead of the A to be able to delete contacts from any table?

