Bug 60099 - StatementCache does not check the scrollable type of result set when searching for a cached statement
Summary: StatementCache does not check the scrollable type of result set when searchin...
Status: RESOLVED FIXED
Alias: None
Product: Tomcat Modules
Classification: Unclassified
Component: jdbc-pool (show other bugs)
Version: unspecified
Hardware: PC All
: P2 major with 1 vote (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-08 20:30 UTC by Mohamad ABBAS
Modified: 2016-09-15 10:20 UTC (History)
1 user (show)



Attachments
Test class (3.60 KB, text/x-java)
2016-09-08 20:30 UTC, Mohamad ABBAS
Details

Note You need to log in before you can comment on or make changes to this bug.
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