Delete Data using MySQL Database and Java with Netbeans IDE


This tutorial entitled Delete Data using MySQL Database and Java with Netbeans IDE will help you on how to create a Delete features using your Java and Netbeans.

This is the continuation of my last topic entitled How to Load Data from MySQL Database to Table Element in Java. This program can delete data from a selected row of data from Java table. Follow all the steps to complete this tutorial.

Delete Data using MySQL Database and Java with Netbeans IDE

  1. Add a new button inside your load data form and rename the button text to “Delete”. We use that button for our delete function.

2. Double click the new created button and insert the following codes below.

int row=jTable1.getSelectedRow();
String id = (jTable1.getModel().getValueAt(row, 0).toString());
String nna = (jTable1.getModel().getValueAt(row, 1).toString()) + ” ” + (jTable1.getModel().getValueAt(row, 2).toString());

int p = JOptionPane.showConfirmDialog(null, “Are you sure you want to delete ” + nna + “?”,”Delete”,JOptionPane.YES_NO_OPTION);
if (p==0){
String str=”DELETE FROM userinfo WHERE idUserInfo='” + id + “‘”;
JOptionPane.showMessageDialog(null,”Sucessfully Deleted!”);
}catch(Exception e){
JOptionPane.showMessageDialog(rootPane, e);

3. Run your program and the output should look like the image below. When the user click the delete button, a confirmation box appear asking the user to delete the item or not. If the user select yes, the data selected from the table will be deleted.

Related Articles You May Like:


Looking for more source code? Type your keyword here here!


Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.