File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes SQL Remove. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL Remove." Watch "SQL Remove." New topic
Author

SQL Remove.

david foley
Ranch Hand

Joined: Dec 01, 2012
Posts: 82
I am working on a Database GUI that has Text Fields.

I have the following Buttons Workings, Insert, Connect to Database, Next, Previous, Insert and Search by last Name.

I am Trying to Get the Delete Button Working, which i am getting Errors.










I am Getting the Following Errors.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18989
    
    8

I don't think that's a valid DELETE statement. You appear to have started to write a DELETE and then tacked on part of the INSERT syntax at the end of it. The simplest form of DELETE is


david foley
Ranch Hand

Joined: Dec 01, 2012
Posts: 82
I have tried

Delete from patient where patientId = ?

But that does not seem to work either

Some how I am trying
To be able to remove a account that has populated the text fields of the program
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18989
    
    8

Well, that's the way to do it. So if it "doesn't work" then you must not be doing it right. But have a look at our FAQ entry ItDoesntWorkIsUseless (<== click on that link) and then post accordingly.
david foley
Ranch Hand

Joined: Dec 01, 2012
Posts: 82
Ok, by looking at my code above where do you think i am after going wrong.

i can i get the Code to Pick up on What User im on and to Remove that User.

i am using nothing but text fields
Wei Dai
Ranch Hand

Joined: Jun 22, 2005
Posts: 86
removePerson = connection.prepareStatement(
"DELETE FROM Patient where PatientId=? and FirstName=? and LastName=? and Address=? and PhoneNumber?" );
david foley
Ranch Hand

Joined: Dec 01, 2012
Posts: 82
i have used this Query


"DELETE History, Patient " +
" FROM " +
" History INNER JOIN Patient ON History.PatientId = Patient.PatientId " +
" WHERE (Patient.PatientId)= ?" );

This Works only when the Two Tables are Filled with Info.. E.G Patient Number 18 is also on History Table This Code Removes the Patient from Both Tablets, But if Patient 19 is only on Patient Table it will Tell me Patient Not Removed.
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3611
    
  60

I'm not sure all databases support deleting from views/joins. I would recommend to delete the data in two separate queries: first from the child table, then from the parent table. That is guaranteed to work in all databases out there.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: SQL Remove.