0

hi, please help me debug this,
i am trying to add one row from one table to another at the same delete it
from the table i am getting it from. (cut and paste kinda thing).

Only one part works, i can only copy and not delete.

int recordAffected = 0;
        int recordAffected2 = 0;
    try {
    id = request.getParameter("id"); 
    String sql = "INSERT INTO dispatchedapplicants SELECT * FROM applicants WHERE id=" + id; 
      String sql2 = "DELETE FROM applicant WHERE id=" +id;
      Connection con = 
        DriverManager.getConnection("jdbc:mysql://localhost:3306/passport","root", ""); 

      Statement s = con.createStatement(); 
      Statement s2 = con.createStatement();
      recordAffected = s.executeUpdate(sql); 
      recordAffected2 = s2.executeUpdate(sql2);
      s.close(); 
      con.close(); 
    } 
    catch (SQLException e) {
    } 
    catch (Exception e) {
    } 
    if ((recordAffected!=0)&&(recordAffected2!=0)){ 
     System.out.println("Recorded added to second table and deleted from the" 
         + "first succesfully.");
       }
    else{
        System.out.println("Record could neither be added nor deleted.");
       }
1
Contributor
1
Reply
2
Views
5 Years
Discussion Span
Last Post by eLu-sive
0

Minor hiccup. All solved. :)

int recordAffected = 0;
        int recordAffected2 = 0;
    try {
      id = request.getParameter("id"); 
      String sql = "INSERT INTO dispatchedapplicants SELECT * FROM applicants WHERE id=" + id; 
      String sql2 = "DELETE FROM applicants WHERE id=" +id;
      Connection con = 
        DriverManager.getConnection("jdbc:mysql://localhost:3306/passport","root", ""); 

      Statement s = con.createStatement(); 
      Statement s2 = con.createStatement();
      recordAffected = s.executeUpdate(sql); 
      recordAffected2 = s2.executeUpdate(sql2);
      
      s.close(); 
      s2.close();
      con.close(); 
    } 
    catch (SQLException e) {
    } 
    catch (Exception e) {
    } 

   if ((recordAffected!=0)&&(recordAffected2!=0)){ 
      System.out.println("<P>Record added.Record deleted.</P>");
      
    }
    else 
      System.out.println("<P>Error deleting record.</P>");
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.