i have 2 tables in a database patients and reports
depending on the certain conditions i either update both tables (patients followed by reports) or just reports
this is my code for updation of patients followed by reports
Code:
SQLStmt ="insert into patients (ssn, name, dob) "
+ "values('"
+ data[1]
+ "','"
+ data[2]
+ "','"
+ data[3]
+ "');";
stmt.execute(SQLStmt);
// retrive patient_id
SQLStmt ="select patient_id from patients where ssn = '"
+ data[1]
+ "';";
rs1 = stmt.executeQuery(SQLStmt);
// insert record in reports
SQLStmt = " insert into reports (patient_id, report_date) "
+ "values('"
+ rs1.getString("patient_id") // line 82
+ "','"
+ data[0]
+ "');";
stmt.execute(SQLStmt);
when i am trying to update both the tables ... an update on 'reports' can be done only after getting the patient_id (primary key, auto generated)from 'patients' i get the following error
java.sql.SQLException: Before start of result set
at com.mysql.jdbc.ResultSet.checkRowPos(ResultSet.java:3624)
at com.mysql.jdbc.ResultSet.getString(ResultSet.java:1763)
at com.mysql.jdbc.ResultSet.getString(ResultSet.java:1827)
at uds.util.Update.updateDb(Update.java:82)
at call.main(call.java:33)
wht could be the problem
thanks in advance