wood burning stoves 2.0*
The moose likes JDBC 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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Deleting a Record from a database" Watch "Deleting a Record from a database" New topic
Author

Deleting a Record from a database

Jo Eagle
Greenhorn

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?
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

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: http://aspose.com/file-tools
 
subject: Deleting a Record from a database
 
Similar Threads
Login Servlet
MySQL update issue
How can I Insert vector elements into a DB??
how to search?
Validation for Text Area