2 Replies Latest reply: Feb 24, 2008 11:16 PM by 796215 RSS

    How to retrieve last record entered into database

    807603
      Hi all,

      I want to retrieve the last resord entered into a database table.
      I have a MS Access database.
      This code does not return the last record but its my nearest attempt to.

      Can anyone suggest the correct SQL or Solution.

      Help is greatly appriciated.

      Thanks.

      String str = "SELECT * FROM Missions WHERE Mission = (SELECT MAX(Mission) FROM MISSIONS)";
              ResultSet rs = null;
                  String f1 = null, f2 = null, f3 = null, f4 = null; 
                  try{    
                      rs = statement.executeQuery(str);
                      txtMissionInformation.setText("");
                      int row = 0;
                      while(rs.next()){
                          f1 = rs.getString(1);
                          f2 = rs.getString(2);
                          f3 = rs.getString(3);
                          f4 = rs.getString(4);
                          System.out.println(f1 + " " + f2 + " "+f3+" "+f4);
                          txtMissionInformation.append(f1 + ", "+ f2 + ""+","+f3+","+f4);
                      }
                      System.out.println("Query Complete !");
                  } catch(Exception e){
                      e.printStackTrace();
                  }