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 1 of 1

Thread: How to Delete selected table data from DB???? HELP

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

    Default How to Delete selected table data from DB???? HELP

    I'm trying to delete a selected row from a jTable that was queried from a database. I'm getting stuck on how to create an actionlistener that deletes the selected (highlighted) data from the database, here is what I have. I know after the connection it is probably totally wrong but I think you can get the idea from it....

     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {   
     
     
     
    DefaultTableModel model=(DefaultTableModel)jTable1.getModel();
            try{
               Class.forName("java.sql.Driver");
               Connection con=DriverManager.getConnection ("jdbc:mysql://Lane-PC:3306/JavaApp","user","user");
     
           PreparedStatement ps = con.prepareStatement("DELETE FROM supportTickets (?,?,?,?,?,?)");
             ps.executeUpdate(jTable1.getSelectedRows());   
            }
     
           catch (SQLException se){
                JOptionPane.showMessageDialog(null,"SQL Exception, Database Connection Error","error",JOptionPane.PLAIN_MESSAGE);
     
               while (se !=null){
                   System.out.println("State :"+ se.getSQLState());
                   System.out.println("Message :"+ se.getMessage());
                   System.out.println("State :"+ se.getErrorCode());
     
                   se = se.getNextException();
     
               }
            } catch (Exception e){
                System.out.println(e);
            }
        }
    Last edited by lanepulcini; February 21st, 2012 at 07:14 PM.


Similar Threads

  1. Retrieve data from other table
    By kichkich in forum JDBC & Databases
    Replies: 2
    Last Post: June 23rd, 2011, 07:51 AM
  2. Replies: 2
    Last Post: June 15th, 2011, 03:49 PM
  3. Replies: 1
    Last Post: June 11th, 2011, 05:39 AM
  4. 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
  5. how to delete record based on checkbox selected checkbox
    By -_- in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: December 15th, 2009, 09:26 PM