Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How to delete several data in database using java?

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to delete several data in database using java?

    Hi. I want to delete some specific data from my jtable.I made a table named student where i want to delete several data.Here remain 3 column stu_info,stu_name & Blood_group.To take input i used jtextfield and to delete i used delete button. I used the following code to delete.

    private void cmd_deleteActionPerformed(java.awt.event.ActionEve nt evt) {

    int p= JOptionPane.showConfirmDialog(null,"Do you really want to delete?","Delete",JOptionPane.YES_NO_OPTION);
    if(p==0){


    String sql="Delete from student where stu_id=? AND stu_name=? AND Blood_group=?";
    try{
    pst=conn.prepareStatement(sql);

    pst.setString(1, jTextField1.getText());
    pst.setString(2, jTextField2.getText());
    pst.setString(3, jTextField3.getText());

    pst.execute();

    }
    catch(Exception e){
    JOptionPane.showMessageDialog(null, e);
    }
    Update_table();
    }
    }

    But here to delete a row i have to i have to put all 3 value of my 3 column as input. Sometimes i wanna delete some rows which contain a specific value of a column.(for example i want to delete all row contain Blood_group=O+) . Sometime i want to delete the rows which caontain a specific value of a column & another specific value of another column.(for example delete all row containing Blood_group=B+ and stu_name=mark). How can i do that? Please help.Here is the jframe view of my program.

    Capture.jpg


  2. #2
    Junior Member
    Join Date
    Nov 2012
    Location
    Germany
    Posts
    20
    My Mood
    Bored
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: How to delete several data in database using java?

    Put your code in [code] tags please.

Similar Threads

  1. Replies: 3
    Last Post: September 3rd, 2012, 11:36 AM
  2. Replies: 1
    Last Post: June 29th, 2012, 01:29 PM
  3. delete item from mysql database
    By some_one in forum AWT / Java Swing
    Replies: 3
    Last Post: April 9th, 2012, 10:32 AM
  4. How to Delete selected table data from DB???? HELP
    By lanepulcini in forum JDBC & Databases
    Replies: 0
    Last Post: February 21st, 2012, 07:07 PM
  5. How to delete data from php through GUI in Java?
    By BluXit in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 26th, 2010, 09:41 AM

Tags for this Thread