aspose file tools*
The moose likes JDBC and the fly likes Delete Records form Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Delete Records form Database" Watch "Delete Records form Database" New topic
Author

Delete Records form Database

Sander Silva
Greenhorn

Joined: May 15, 2011
Posts: 28
Hi All,
I need to Delete Records form MS Access Database.

I have 2 files.

1 to get value from Gui and 2nd contains SQL code.

I think problem is mainly in my SQL statement rather than in Java code.

What I want to do is, get the integer value (SVID) from GUI and
Delete all records match the SVID in the Main table of my database.

DeleteCode.java


DeleteGui.java


Please kindly help.

Fatih Keles
Ranch Hand

Joined: Sep 01, 2005
Posts: 182
You should use PreparedStatement and it's setX methods.

Sander Silva
Greenhorn

Joined: May 15, 2011
Posts: 28
Thank you so much

It's working 100%, I can delete the ID i need

but, I'm getting this error

Error: java.lang.NullPointerException
Fatih Keles
Ranch Hand

Joined: Sep 01, 2005
Posts: 182
It can be anything, can you provide a stack trace and more code?
Sander Silva
Greenhorn

Joined: May 15, 2011
Posts: 28
Thank you again for kind help,

Here's more code



and



Fatih Keles
Ranch Hand

Joined: Sep 01, 2005
Posts: 182
Statement s is never initialized but you try to close it in your closeDb() method which is generating the NullPointerException since s is null.

After exception your database connection is not closed!!!. You should use finally blocks so that you don't leave any connection open and Exceptions are easy to be determined if you use printStackTrace method of Exception object.
Sander Silva
Greenhorn

Joined: May 15, 2011
Posts: 28
Thank you very much!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Delete Records form Database