0% found this document useful (0 votes)
45 views1 page

CODE For The Delete Button: Private Void Null

The document provides code for a delete button that deletes a product ID from a database table. When the button is clicked, a dialog box prompts the user to enter a product ID. The code then connects to the database, checks if the entered ID exists, and if so deletes the matching record and displays a confirmation message. If the ID does not exist, it displays an error.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views1 page

CODE For The Delete Button: Private Void Null

The document provides code for a delete button that deletes a product ID from a database table. When the button is clicked, a dialog box prompts the user to enter a product ID. The code then connects to the database, checks if the entered ID exists, and if so deletes the matching record and displays a confirmation message. If the ID does not exist, it displays an error.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

 once it is clicked a JOptionInputDialog will appear

Once the ID Number was entered it will be automatically deleted from the database

CODE for the Delete Button

Note: Regards that the import java.sql.*; and import javax.swing.*; is already on the top of the public class….

private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {

String id=JOptionPane.showInputDialog(null,"Enter Product ID You want to delete","Commonwealth High


School",JOptionPane.INFORMATION_MESSAGE);

try{

Connection kon;

ResultSet rs;

Statement stmt;

String query;

String url= "jdbc:odbc:konekted";

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

kon = DriverManager.getConnection(url, "", "");

stmt = kon.createStatement();

String qry="Select * FROM TblProducts WHERE PROID='"+id+"'";

rs = stmt.executeQuery(qry);

if(rs.next())

query = "DELETE FROM TblUsers WHERE PROID='"+id+"'";

int j = stmt.executeUpdate(query);

JOptionPane.showMessageDialog(null,"Successfully Deleted "+j,"Commonwealth High


School",JOptionPane.INFORMATION_MESSAGE);

else

JOptionPane.showMessageDialog(null,"No data found ","Commonwealth High


School",JOptionPane.ERROR_MESSAGE);

stmt.close();

kon.close();

catch(Exception e){}

You might also like