Delete a Record

Delete a Record

 

Deleting a row can be straightforward: Just use deleteRow method of the ResultSet:

rs.deleteRow( );

However, the Driver we are using, the ClientDriver, leaves a blank row in place of the data that was deleted. If you try to move to that row using your Next or Previous buttons, the ID Text Field will have a 0 in it, and all the others will be blank.

To solve this problem we’ll first delete a row then, again, close the Statement object and the ResultSet objects. We can then reload all the data in the Text Fields. That way, we won’t have any blank rows.

Here’s the code to add for your Delete Record button:

Java code that deletes a record

Run your programme and test it out. You now be able to delete records from your database.

 

And that’s it – you now have the basic knowledge to write a database programme in Java using a GUI. Congratulations, if you got this far!

Advertisements

Give A message for us

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s