• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Delete Records form Database

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 182
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should use PreparedStatement and it's setX methods.

 
Sander Silva
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 182
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It can be anything, can you provide a stack trace and more code?
 
Sander Silva
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you again for kind help,

Here's more code



and



 
Fatih Keles
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic