Wednesday, June 26, 2013

Re: getGeneratedKey() throws Exception

how does it fail? What's the SQLException or error?


On Wed, Jun 26, 2013 at 9:13 AM, Jonas Gabriel <soli.gabriel@googlemail.com> wrote:
Hi!
I have a problem with getting the key value after inserting a new row into Google Cloud SQL.
I could have sworn it worked before, but now somehow it doesn't...

String statement = "INSERT INTO xxxx ( xx) VALUES (?)";
PreparedStatement stmt = c.prepareStatement(statement, Statement.RETURN_GENERATED_KEYS);
stmt.setString(1, xx);
int i = 2;
i = stmt.executeUpdate();
if (i == 1) {
ResultSet result = stmt.getGeneratedKeys();
String resultCode = "1";
while (result.next()) {
resultCode = result.getString("xxid");
}
}

I can see the insert in my Database, so that works. And if I delete the stmt.getGeneratedKeys(); Method, everything works fine. But when I add that line, the query fails. What am I doing wrong here? (Makes no difference if I user RETURN_GENERATED_KEYS or 1...)

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment