• 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 verification addon in my jframe form

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working on a basic CRUD application in Java. I have a JFrame form with add, delete, edit and update options. I have designed the delete button with just the ability to search by user ID and delete the entire record from table, but I am confused on what to do if the ID doesn't exist or the ID is already deleted. I get the same message in all three scenarios in my try catch block. Can someone help me design errors to show when the user ID doesn't exist and when the user ID is already deleted?

 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can tell if the SQL statement actually deleted any data by checking the return value of the execute() call and then calling the appropriate getXXX method to get the resultSet or update count. For an SQL delete statement execute should return false and getUpdateCount() should return the number of rows that were updated. Alternatively you could call executeUpdate() instead of execute() which directly returns the number of rows effected by the operation.

BTW You can't distinguish between doesn't exist and already deleted unless your application/database keeps a record of used ID's or deleted ID's or, if the ID's are contiguous, the current maximum ID.
 
Farhan Karim
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you provide an example ??
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Tony Docherty
Bartender
Posts: 3323
86
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BTW I should add that prepared statements are normally used where you prepare the statement in advance inserting '?' where you want to add values at a later date. You can then reuse the prepared statement each time you want to execute that particular SQL statement. See this tutorial: http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html.

Also without seeing all your code it's hard to be sure but I suspect you aren't closing the statement and/or connection on all execution paths after you have finished with them.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic