I have this query which on executing in my sql command line client executes fine and get entry in both tables but executing it gives me error.
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the man
ual that corresponds to your MySQL server version for the right syntax to use near ‘INSERT INTO tm_belonging(B
ID,BELONGING_TYPE,BELONGING_TEXT)VALUES(LAST_INSERT_ID’ at line 1
String sql="INSERT INTO tm_visitor(VISITOR_TEXT,COMPANY_TEXT,CONTACT,PERSON_TO_MEET,DEPARTMENT_TEXT,FLOOR)Values(?,?,?,?,?,?);"+"INSERT INTO tm_belonging(BID,BELONGING_TYPE,BELONGING_TEXT)VALUES(LAST_INSERT_ID(),?,?);";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setString(1,VisitorName.toUpperCase());
pst.setString(2,Company.toUpperCase());
pst.setString(3,Contact);
pst.setString(4,WhomeToMeet.toUpperCase());
pst.setString(5,Department);
pst.setString(6,DepartmentFloor);
pst.setString(7,BType);
pst.setString(8,Belonging);
pst.executeUpdate();
pst.close();
mmm try this:
if this dont work you must use one prepared statement for query