Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Deleting a Record from a database

 
Jo Eagle
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having trouble with the SQL code - not sure if this is right can anyone help me out.Do I have to make another class?
Code------
public void deleteRecord(){
guestLastName = txtLastName.getText();
guestFirstName = txtFirstName.getText();
guestEmail =txtEmail.getText();
guestStreetAddress =txtStreetAddress.getText();
guestCity =txtCity.getText();
guestState = txtState.getText();
guestZip =txtZip.getText();
guestHPhone = txtHPhone.getText();
guestWPhone = txtWPhone.getText();
guestCell = txtCell.getText();
guestFax = txtFax.getText();
guestEmployer = txtEmployer.getText();
guestMisc = txtMisc.getText();

try{ SQL = "Delete From AddressBook Where LastName = ('"+guestLastName+"','"+guestFirstName ','"+guestEmail+"','"+guestStreetAddress+"','"+ "','"+guestState+"','"+guestZip+"','"+guestHPhone+"','"+ guestWPhone+"','"+guestCell+"','"+guestFax+"','"+
guestEmployer+"','"+guestMisc+"');";
}catch(Exception e){
System.out.println("Fail to Load JDBC?ODBC driver.");
}}}
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A normal SQL delete statement looks like this:


delete from bartender where last_name = "Paul"


I have no idea why you have a try..catch in there as all you are doing is creating a String.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic