We have two different databases in a project; an Oracle and a MySql one. Both of them need connection pooling for a better performance. First, I add dbcp context for mysql to my application context. The settings were quite straightforward. But when I try to use the same settings (except for the connection url and the driver class name of course) for the Oracle data source I got the following exception:
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (ORA-00923: FROM keyword not found where expected
which can be translated as "there's some FROM statement missing somewhere while setting your connection". My validation query for MySql was just "SELECT 1" which annoys Oracle database. I change it to "SELECT 1 FROM DUAL" and it's fixed.
Showing posts with label spring jdbc. Show all posts
Showing posts with label spring jdbc. Show all posts
Monday, June 13, 2011
Monday, May 30, 2011
EmptyResultDataAccessException in your face
Recently I get an EmptyResultDataAccessException in a project where we use Spring JDBC. The full exception listing is "org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0". When I trace the exception I see that I'm calling queryForLong() method of JdbcTemplate for "SELECT Column FROM TABLENAME" on an empty table. Column here is of Long type. Now, I plan to catch the exception and return an unusual value (like -1) as a result. On the service layer, I plan to check for equality to the unusual value and proceed with the right logical flow.
Notice that if you use some function like count(), min(), max() ... in the same query (SELECT MAX(Column) FROM TABLENAME) you won't get the same exception but a "0" result instead.
Notice that if you use some function like count(), min(), max() ... in the same query (SELECT MAX(Column) FROM TABLENAME) you won't get the same exception but a "0" result instead.
Subscribe to:
Posts (Atom)