title: How to get last inserted id into jdbc in jsp
body: <p>How can I get ID from just inserted row in jsp?</p>
  
  <pre><code>        PreparedStatement ps = con.prepareStatement("INSERT INTO Recipients(CustomerID,Name, Street, City, ZipCode, PhoneNumber, EmailAddress,"
              + " ContactPersonName, ContactPersonSurname, ContactPersonPhoneNumber,ContactPersonEmailAddress) "
              + "values(?,?,?,?,?,?,?,?,?,?,?)");
  </code></pre>
  
  <p>And I need use id from Recipients to insert it into Parcels</p>
  
  <pre><code>PreparedStatement ps2 = con.prepareStatement("INSERT INTO Parcels(TransportTypeID,CustomerID,RecipientID,ParcelAmount, DimLength, DimHeight, DimWidth, ParcelWeigth, Content,"
              + " AdditionalDescription, IsCustomParcel, ReceiptFee, InsuranceAmount, OwnPick, DispatchDate) "
              + "values((?,?,?,?,?,?,?,?,?,?,?,?,?,?,?");
  
      ps2.setString(1,transportTypeID);
      ps2.setString(2,customerID);
      ps2.setInt(3,recipientID); ...
  </code></pre>
  
  <p>I was trying to use ResultSet:</p>
  
  <pre><code>int recipientID=0;
      ResultSet rs2=st.executeQuery("SELECT * FROM Recipients");
      if(rs2.last())
             {
              recipientID = rs2.getInt("RecipientID");
             }
  </code></pre>
  
  <p>but it didn't work.</p>