我有一个BasicDataSource实例,jdbctemplate使用它。
因此,经过一段空闲时间后,它总是说:
Caused by: java.sql.SQLException: Could not retrieve transation read-only status server
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1084)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:949)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:939)
at com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3976)
at com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3947)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2295)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2262)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2246)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:916)
at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:909)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:644)
... 39 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 30,457,725 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1127)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3715)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3604)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4155)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2615)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2832)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2781)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1569)
at com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3970)
... 48 more
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3161)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3615)
... 56 more
数据源的bean定义是:
<bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://1.2.3.4:3306/?autoReconnectForPools=true"/>
<property name="username" value="root"/>
<property name="password" value="password"/>
<property name="initialSize" value="${datasourceInitialPoolSize}"/>
</bean>
有什么想法吗?
答案 0 :(得分:0)
检查mysql服务器是否已启动。尝试在服务器计算机上运行mysql&#34; mysql客户端。如果服务器无法连接,您尝试连接的频率并不重要。
答案 1 :(得分:0)
数据库连接不会永远持续下去。连接池通常允许测试池连接的有效性。您的** Number of RTC controllers. */
typedef enum { RTC_0 = 0, RTC_NUM } rtc_t;
/** RTC register map. */
typedef struct {
RW uint32_t rtc_ccvr; /**< Current Counter Value Register */
RW uint32_t rtc_cmr; /**< Current Match Register */
RW uint32_t rtc_clr; /**< Counter Load Register */
RW uint32_t rtc_ccr; /**< Counter Control Register */
RW uint32_t rtc_stat; /**< Interrupt Status Register */
RW uint32_t rtc_rstat; /**< Interrupt Raw Status Register */
RW uint32_t rtc_eoi; /**< End of Interrupt Register */
RW uint32_t rtc_comp_version; /**< End of Interrupt Register */
} rtc_reg_t;
/* RTC register base address. */
#define RTC_BASE (0xB0000400)
/* RTC register block. */
#define RTC ((rtc_reg_t *)RTC_BASE)
//--------------------------------------------------------------------------
//function declaration
int qm_rtc_set_alarm(const rtc_t rtc, const uint32_t alarm_val)
//--------------------------------------------------------------------------
int main(void)
{
#define ALARM (RTC_ALARM_MINUTE / 6)
rtc_set_alarm(RTC_0, (RTC[RTC_0].rtc_ccvr + ALARM));
}
支持您可能会考虑使用的几个相关属性:testOnBorrow,testOnReturn,testWhileIdle,validationQueryTimeout和validationQuery。
如果您希望确保从池中获得的连接良好,请使用testOnBorrow。验证查询可以很简单,只要它至少返回一行即可。例如,&#34;选择1&#34;。