Bug 60099

Summary: StatementCache does not check the scrollable type of result set when searching for a cached statement
Product: Tomcat Modules Reporter: Mohamad ABBAS <mabbas85>
Component: jdbc-poolAssignee: Tomcat Developers Mailing List <dev>
Severity: major CC: mabbas85
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Test class

Description Mohamad ABBAS 2016-09-08 20:30:21 UTC
Created attachment 34224 [details]
Test class

When the StatementCache is searching for a matching PreparedStatement, the matching criteria do not take into account the scrollable type of result set, but only the sql query.

If we create a PreparedStatement with a FORWARD_ONLY result set type, and then we try to create another PreparedStatement with a SCROLL_INSENSITIVE type with the same query, then the cache will return the PreparedStatement created first(a FORWARD_ONLY statement), and any attempt to call the absolute method will throw a java.sql.SQLException: The 'absolute()' method is only allowed on scroll cursors.

Please find attached a Test Class that can help to reproduce the problem. To run this class you need to add derby-10.11, tomcat-jdbc-8.0.37 and tomcat-juli-8.0.37 to classpath. I am using jdk1.8.0_92 to compile and execute this test.

P.S. The error only appears when creating a PreparedStatement instead of a Statement (by calling createStatement()).

Please tell me, if you need more informations.

Thanks for your help!

Full StackTrace:
Exception in thread "main" java.sql.SQLException: The 'absolute()' method is only allowed on scroll cursors.
	at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
	at org.apache.derby.impl.jdbc.EmbedResultSet.checkScrollCursor(Unknown Source)
	at org.apache.derby.impl.jdbc.EmbedResultSet.absolute(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.tomcat.jdbc.pool.interceptor.StatementDecoratorInterceptor$ResultSetProxy.invoke(StatementDecoratorInterceptor.java:307)
	at com.sun.proxy.$Proxy4.absolute(Unknown Source)
	at test.Test.testWithInsensitiveResultSet(Test.java:75)
	at test.Test.main(Test.java:18)
Caused by: ERROR XJ061: The 'absolute()' method is only allowed on scroll cursors.
	at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
	at org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown Source)
	... 14 more
Comment 1 Keiichi Fujino 2016-09-15 10:20:15 UTC
Thanks for the report.
The fix will be in :
- 9.0.x for 9.0.0.M11 onwards
- 8.5.x for 8.5.6 onwards
- 8.0.x for 8.0.38 onwards
- 7.0.x for 7.0.73 onwards