How can I get ID from just inserted row in jsp?
PreparedStatement ps = con.prepareStatement("INSERT INTO Recipients(CustomerID,Name, Street, City, ZipCode, PhoneNumber, EmailAddress,"
+ " ContactPersonName, ContactPersonSurname, ContactPersonPhoneNumber,ContactPersonEmailAddress) "
+ "values(?,?,?,?,?,?,?,?,?,?,?)");
And I need use id from Recipients to insert it into Parcels
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); ...
I was trying to use ResultSet:
int recipientID=0;
ResultSet rs2=st.executeQuery("SELECT * FROM Recipients");
if(rs2.last())
{
recipientID = rs2.getInt("RecipientID");
}
but it didn't work.