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 Java 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.

[java]try{
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 + “‘”;
pst=conn.prepareStatement(str);
pst.execute();
JOptionPane.showMessageDialog(null,”Sucessfully Deleted!”);
}
}catch(Exception e){
JOptionPane.showMessageDialog(rootPane, e);
}[/java]

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.

About The Delete Data using MySQL Database In Java

Project Name:Delete Data using MySQL Database
Language/s Used:JAVA
Database:MySQL
Type:Desktop Application
Developer:IT SOURCECODE
Updates:0
Delete Data using MySQL Database In Java– Project Information

Related Articles You May Like:

 

Leave a Comment