How to delete the data from the Database

Hello guys, This is vishal and If you already inserted some data in the database and wants to delete that data but don’t know how to delte then don’t worry i am here to tell you in details that how to delete the data from the database in simple steps. you just only have to follow me.

So, Guys it is very easy to do in java you just need to write some lines of code and everything is done.
Here is my video in which I am showing that how to delete the data.

Now, after watching this video you know very clearly that how to delete the data but still, I provide the code and you only just copy and paste it in your IDE and enjoy.


But before writing the code you have to write this 2 line outside your button section.
Connection conn;
PreparedStatement st;

And Code is:

        String name = uname.getText();

        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/insertdata","root","");
            st = conn.prepareStatement("delete from insertdata where username = ?");
            st.setString(1,name);
            
            st.executeUpdate();
            JOptionPane.showMessageDialog(this, "Data Deleted Successfully");
            
            uname.setText("");
            uname.requestFocus();
            
            
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(insertdata.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(insertdata.class.getName()).log(Level.SEVERE, null, ex);
        }
        

You can also watch another video in that video I am showing you that how to insert the data into the database.
https://www.youtube.com/watch?v=BDVQxN-3fAs

So, guys all the stuff you get to delete the data from the database then why are you waiting to go and execute the code.
Thank You, guys.

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart