Thursday, May 5, 2011

JDBC comments

Today we deployed a new version of an application which uses a Sybase stored procedure to transfer some data across. On the first attempt to process some data we got a very interesting yet weird error in our logs when the application tried to execute this stored procedure:

SQL Error: 102, SQLState: 42000
com.sybase.jdbc3.jdbc.SybSQLException: Incorrect syntax near '@p0'.

Our log revealed the stored procedure to be called however as:
exec some_stored_procedure(3)

We figured something was probably wrong with the stored procedure so used a SQL client to perform the same call. Funnily enough the stored procedure worked just fine.

Something had to be wrong with our code yet we had not changed any code related to executing the stored procedure.

We reverted to a previous build where the error didn't occur and verified everything was working ok in that version.

We then configured log4jdbc to see the exact SQL going over the wire, ran the previous version of the application and then tried the faulty new build.

The SQL being executed was exactly the same save for one minute detail: in the new build all JDBC queries were prefixed by /* ... */ comments. Surely this couldn't be the source of the problem as all insert and update operations were being executed just fine and were also prefixed by comments.
Also we hadn't changed anything to do with emitting JDBC comments, or had we? We looked at the Hibernate config in the Spring application context file and found out that indeed hibernate.use_sql_comments had the value of 'true'.
So we changed this to false and reran the the code that triggered the stored procedure.
Everything was now working well.

I guess Sybase really doesn't like JDBC comments in combination with stored procedures ...

0 comments:

Post a Comment