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.");
       }

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>");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.