tomcat dbcp 基于jndi配置时出现java.sql.SQLException: Already closed

最近观察生产环境发现一个现象,一段时间不操作,再重新操作时,数据库连接第一次会出现:java.sql.SQLException: Already closed.,如下:

数据源是用tomcat dbcp 基于jndi配置管理的,查了下,如下:

原因:

You‘re probably running into the fact that MYSQL closes connections  which have been open "too long".

Probably if you make the request to the server again, you‘ll find that  it works because the connection is reopened.

解决方法:

One way to deal with this is to add the following to your context.xml  Resource:

validationQuery="select 1" 
(基于mysql)

validationQuery="select
1 from dual"  (基于oracle)

代价:

This causes a very cheap test query to always be run first; if the  connection has been closed, this gets the failure,
and

then a new connection is opened.

细想下原来用weblogic jdbc jndi的配置有一个专门的配置项来配置这个test query,配置tomcat时粗心大意了 :(

tomcat dbcp 基于jndi配置时出现java.sql.SQLException: Already closed

时间: 2024-10-06 07:24:12

tomcat dbcp 基于jndi配置时出现java.sql.SQLException: Already closed的相关文章

今天线上系统碰到个怪问题DBCP数据连接异常,java.sql.SQLException: Already closed.

java.sql.SQLException: Already closed. at org.apache.commons.dbcp.PoolableConnection.close(PoolableConnection.java:84) ~[commons-dbcp-1.2.2.jar:1.2.2] at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.jav

连接mysql时提示java.sql.SQLException: Access denied for user 'root'@'DESKTOP-N2B2D9A' (using password: YES)

用root连接mysql时提示:访问被拒绝 检查一下mysql server是否开启,发现后台在运行着..  然后查了一下mysql的用户表,发现root只能运行使用本地ip(localhost或者127.0.0.1)进行连接 解决方法:新开一个权限GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'jeffw' WITH GRANT OPTION; 然后查询一下:select * from user; 新开的root的已经开启权限,

java.sql.SQLException: Access denied for user 'root'

程序在连接远程 mysql服务器时出错 java.sql.SQLException: Access denied for user 'root'@'192.168.27.129' (using password: YES) 本机IP为'192.168.27.129' 进入mysql命令行: MySQL>use mysql; MySQL>select host,user from user; 查看得信息如下,也没有限制不让本机连接mysql呢. +-----------------------+

java.sql.SQLException: Field 'id' doesn't have a default value(用eclipse操作数据库时报了这种奇怪的错误)的原因与解决方法

1.错误原因 由于id在数据库表中是作为主键,但是在插入的过程中,没有给予数值,并且没有让其自增 2.解决办法 修改数据库表中的id,让其自增(在插入的过程中,不插入id数据时) java.sql.SQLException: Field 'id' doesn't have a default value(用eclipse操作数据库时报了这种奇怪的错误)的原因与解决方法 原文地址:https://www.cnblogs.com/zyt-bg/p/8385972.html

使用mybatis生成相关文件时java.sql.SQLException: Access denied for user 'root'@'localhost' (using password)

问题:使用mybatis生成相关文件时,dos显示java.sql.SQLException: Access denied for user 'root'@'localhost' (using password) 解决方式:1,先检查数据库的配置文件密码是否错误, 2,检查mybatis-generator.xml的密码是否与数据库的密码相等,因为这个文件的密码不会影响到后台的数据,所以最容易被忽略,造成后台数据可以正常读取,而mybatis却不能生成相关的文件. 使用mybatis生成相关文件

用springboot连接数据库时出现如下错误java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)

将yml配置文件中的参数改一下 用惯了IDEA的快捷提示,没想到居然错了..... 用springboot连接数据库时出现如下错误java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO) 原文地址:https://www.cnblogs.com/qiannianguyao/p/11960884.html

mybatis配置,idea报错:java.sql.SQLException: No suitable driver found for jdbc://localhost:3306/mybatis_test

报错信息: "C:\Program Files\Java\jdk1.8.0_211\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2019.3.4\lib\idea_rt.jar=54826:C:\Program Files\JetBrains\IntelliJ IDEA 2019.3.4\bin" -Dfile.encoding=UTF-8 -classpath "C

java.sql.SQLException: Io 异常: Got minus one from a read call

博客分类: Oracle Tomcat服务器下的应用连接Oracle时报错,出现以下异常: java.sql.SQLException: Io 异常: Got minus one from a read call 查询数据库连接情况: Java代码   SQL> select username,count(username) from v$session where username is not null group by username; USERNAME                 

Cause: java.sql.SQLException: 无法转换为内部表示(Mybatis)

公司开发档案系统使用框架:Spring+Struts2+Mybatis+EasyUI,在开发过程中出现sql异常:“Cause: java.sql.SQLException: 无法转换为内部表示”,错误如下: org.springframework.jdbc.UncategorizedSQLException: ### Error querying database. Cause: java.sql.SQLException: 无法转换为内部表示 ### The error may involv