Friday, August 3, 2012

Re: Exception while trying to call Stored Procedure in Google Cloud: java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '{ call ... }' at line 1

Try removing the space between { and call and see if that works.

Rob

On Thu, Aug 2, 2012 at 12:40 PM, Luis Esteban Acosta Zuñiga <luis.acostaz@gmail.com> wrote:
Hi everyone.
I have a GAE application where I call to stored procedures, it has started throwing this exception the last week:
java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '{ call ... }' at line 1

It was weird because I have a local development enviroment with mysql and App Engine where this application was still running fine.
After several days, I found that the exception is caused by the String I use to call the stored procedure in java.
This String works in local enviroment with mysql and App Engine and is the usual way to call a stored procedure in every java tutorial I've seen:

...
Connection c = null;
CallableStatement spStmt = null;
ResultSet rs = null;

c = DriverManager.getConnection("jdbc:google:rdbms://instance/bd");
spStmt = c.prepareCall("{ call StoredProcName(?) }");
spStmt.execute();
rs = spStmt.getResultSet();
...

But from some day ago it will return this exception when deployed in GAE:

java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' { call StoredProcName(?) } ' at line 1 

The new way to call a stored procedure, that works both in local and GAE environment is removing the opening and closing braces { } :

...
spStmt = c.prepareCall("call StoredProcName(?)");
...

Now my app is working fine(again), something to consider in the future.
Regards.


No comments:

Post a Comment