Re: Can someone tell me what's wrong with my sql statement ?
Posted by: Karen Goh
Date: July 27, 2017 10:57PM

Filipe Silva Wrote:
> Hi Karen,
> Your query should be: "INSERT INTO
> project.tutor_subject (tutor_id) VALUES (" +
> generatedId + ")";
> Mind the spaces around "VALUES" and the missing
> parenthesis around the values section.

Hi Filipe,

There is no error now but I am not able to get the insertion to go into my database :(

stmt2 = (Statement) connection.createStatement();
ResultSet rs = stmt2.executeQuery("SELECT max(tutor_id) as tutor_id from project.tutor");
int tutor_id = 0;
while ({
tutor_id = rs.getInt(1);
int generatedId = 0;
ResultSet tableKeys = ps.getGeneratedKeys();

stmt3 = (Statement) connection.createStatement();
String sql3 = "INSERT INTO project.tutor_subject (tutor_id) VALUES (" + generatedId + ")";
// String sql3 = "INSERT INTO project.tutor_subject (tutor_id) values (LAST_INSERT_ID() from project.tutor)";
if (tableKeys != null)
stmt3.executeUpdate(sql3); // wrong

Options: ReplyQuote

Written By
Re: Can someone tell me what's wrong with my sql statement ?
July 27, 2017 10:57PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.