質問

I have the problem that my web application running on tomcat often drops the following exception:

java.sql.SQLException: Connection already closed

So I want to validate the connection before getting it from the pool by the following config:

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />        
    <property name="url" value="jdbc:mysql://localhost/database" />
    <property name="username" value="user" />
    <property name="password" value="pass" />
    <property name="validationQuery" value="SELECT 1"/>
    <property name="testOnReturn" value="false"/>
    <property name="testOnBorrow" value="true"/>
    <property name="testWhileIdle" value="false"/>
    <property name="maxActive" value="30" />
    <property name="maxIdle" value="15" />
    <property name="minIdle" value="5"/>
    <property name="poolPreparedStatements" value="true"/>
    <property name="connectionProperties"
        value="useUnicode=true;characterEncoding=UTF-8;profileSQL=true;logger=custom.MysqlLogger;" />
</bean>

when sending the following 2 queries with spring jdbcTemplate:

SELECT SQL_CALC_FOUND_ROWS col1, col2, col3 AS foo FROM table HAVING foo = 'bar' LIMIT 0, 10;
SELECT FOUND_ROWS();

The "SELECT FOUND_ROWS()" query always returns 1 because the validation query is executed in between ("SELECT 1").

Does someone know a way to solve this problem without using COUNT in a second query???

役に立ちましたか?

解決

Are both your queries in the same transaction?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top