File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Deleting a Record from a database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Deleting a Record from a database" Watch "Deleting a Record from a database" New topic

Deleting a Record from a database

Jo Eagle

Joined: Feb 14, 2001
Posts: 13
Having trouble with the SQL code - not sure if this is right can anyone help me out.Do I have to make another class?
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+"','"+
}catch(Exception e){
System.out.println("Fail to Load JDBC?ODBC driver.");
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
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.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
I agree. Here's the link:
subject: Deleting a Record from a database
It's not a secret anymore!