Friday, 19 June 2009

Spring JDBC - don't forget to call compile()

If you're using Spring JDBC StoredProcedure and if your application produces errors like that below from time to time. ERROR [...] CallableStatementCallback; uncategorized SQLException for SQL [{? = call foo.bar(??)})}?)}]; SQL state [99999]; error code [17041]; Missing IN or OUT parameter at at index:: 3; nested exception is java.sql.SQLException: Missing IN or OUT parameter at index:: 3 Then check if you call method compile() after defining your IN and OUT parameters otherwise you might expect such an error being thrown during deployment to live system. If compile() is not called explicitly then Spring builds SQL string lazily at first call. If this stored procedure is called in more than one thread in parallel (which is very common scenario) then a race starts. SQL string variable is shared between the threads and as there is no synchronization mechanism involved all threads are appending to it.

0 komentarze: