I am trying to insert the last added id of my chapter table to the lesson table.
Here is my code:
String Sql = "INSERT INTO lesson" +"(title, chapter_id, source)" +"VALUES(?,?,?)"; String getId = "SELECT MAX(id) AS id FROM chapter"; rs = pst.executeQuery(getId); int lastid = rs.getInt("id"); rs.close(); pst=conn.prepareStatement(Sql); pst.setString(2,txt_lessonTitle.getText()); pst.setInt(3,lastid); pst.setString(4,txt_lessonContent.getText()); pst.executeUpdate(); I got an error:
Before start of result set