Cannot create PoolableConnectionFactory (Communications link failure The last packet sent successfu
使用数据库数据源的web 项目,发布后,访问数据库500报错:
浏览器端:

控制台:

数据库连接池在不启动Tomcat的情况下,测试类通过,没有问题。
一旦在服务器发布,就会出现问题,考虑是Tomcat的连接池配置除了问题。
错误提示是:找不到jdbc驱动,但是提示信息里的class值为null,所以,应该是Tomcat没有找到驱动
1、检查是否有jar包:存在,没有问题。
2、检查jar包位置:是在src 下。后来转移到web下,还是没效果。网上资料说:在tomcat6.0中设置jdbc数据源时,jdbc驱动要放在TOMCAT_HOME/lib目录下,绝不能放在web-inf/lib/下面:否则tomcat就会报错说找不到驱动。eclipse中的webcontent是虚拟路径。
3、配置文件:缺失。
解决方案:
增加了配置文件:
content.xml

1 <Context>
2 <Resource
3 auth="Container"
4 driverClassName="com.mysql.jdbc.Driver"
5 maxActive="100"
6 maxIdle="40"
7 maxWait="4000"
8 name="jdbc/fish"
9 username="root"
10 password="root"
11 type="javax.sql.DataSource"
12 url="jdbc:mysql://localhost:3306/fish?useUnicode=true&characterEncoding=UTF-8"
13 />
14 </Context>

运行成功。
转载 关于Tomcat6 的数据源配置:
tomcat6.0 数据库连接池配置问题:
连接池配好后,启动tomat后,输入项目系统的登录名和密码,报
Cannot create JDBC driver of class '' for connect URL 'null' 错误。
经检查,发现是连接池没有配好。
现把连接池配置步骤重新整理一遍。(以ORACLE为例)
1.在tomcat的lib目录下放入数据库驱动。ORACLE的驱动为ojdbc14.jar。
2.修改tomcat目录下的conf目录下的server.xml文件。
在<Host></Host>节点内,增加如下代码
- <Context path="/testApp" docBase="testApp" debug="1" reloadable="flase" crossContext="true">
- <Resource name="jdbc/devDS" type="javax.sql.DataSource" password="shxt" driverClassName="oracle.jdbc.driver.OracleDriver" maxIdle="2" maxWait="5000" username="shxt" url="jdbc:oracle:thin:@192.168.0.133:1521:testApp" maxActive="100"/>
- </Context>
3.在tomcat目录下的conf目录下的Catalina目录下的localhost目录(如果你server.xml文件中HOST节点的name是localhost)下,增加testApp.xml文件。文件内容如下:
- <?xml version="1.0" encoding="UTF-8"?>
- <Context antiResourceLocking="false" privileged="true" useHttpOnly="true" >
- <ResourceLink name="jdbc/devDS" global="jdbc/devDS" type="javax.sql.DataSource"/>
- </Context>
以上为tomcat的配置完成,下面为项目配置的修改。
4.修改项目目录下的web.xml文件。增加jndi信息
- <!-- 数据库JNDI -->
- <resource-ref>
- <description>DB Connection</description>
- <res-ref-name>jdbc/devDS</res-ref-name>
- <res-type>javax.sql.DataSource</res-type>
- <res-auth>Container</res-auth>
- </resource-ref>
5.修改hibernate.cfg.xml信息(如果使用了hibernate)
- <property name="connection.datasource">java:comp/env/jdbc/devDS</property>
到此,tomcat6的连接池配置信息全部完成。
再登录项目,上面的那个错误就不再出现。
Cannot create PoolableConnectionFactory (Communications link failure The last packet sent successfu的更多相关文章
- 【错误】:Could not open JDBC Connection for transaction; nested exception is: Communications link failure;The last packet sent successfully to the server was 1 milliseconds ago
# #错误日志 2016-11-10 16:19:20,834 ERROR [org.quartz.core.JobRunShell] - Job DEFAULT.jobtask threw an u ...
- org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent succ
数据库 没有开启 连接失败 org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause ...
- Oozie时出现Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure?
不多说,直接上干货! 问题详情 [hadoop@bigdatamaster oozie--cdh5.5.4]$ bin/ooziedb.sh create -sqlfile oozie.sql -ru ...
- Communications link failure异常解决
一,异常现象 com.bill99.inf.ibatis.DBException: queryForList error::sqlId=orgOrderAssetsMapping.queryModel ...
- 解决Java程序连接mysql数据库出现CommunicationsException: Communications link failure错误的问题
一.背景 最近在家里捣鼓一个公司自己搭建的demo的时候,发现程序一启动就会出现CommunicationsException: Communications link failure错误,经过一番排 ...
- com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 解决办法
09:00:30.307 [http-8080-6] ERROR org.hibernate.transaction.JDBCTransaction -JDBC begin failed com.my ...
- 异常解决:Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
异常描述 这个异常通常有如下信息: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failu ...
- MySql的Communications link failure解决办法
在使用JDBC连接mysql时可能会遇到以下错误: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications li ...
- Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
很长的报错,截取 ERROR c.a.d.p.DruidDataSource - discard connection com.mysql.jdbc.exceptions.jdbc4.Comm ...
随机推荐
- android git 过滤.idea文件时不起作用。
在Terminal里面执行git命令行 git rm -r --cached .idea 在ignored files中配置.idea/ 文件. 最后.idea变黄就可以了.
- js 浏览器判断
获取浏览器类型 function getBrowser() { var userAgent = navigator.userAgent //取得浏览器的userAgent字符串 var isOpera ...
- 手机端页面自适应解决方案—rem布局进阶版
手机端页面自适应解决方案—rem布局进阶版 https://www.jianshu.com/p/985d26b40199 注:本文转载之处:https://www.cnblogs.com/anni ...
- Spring Boot:定时任务
在我们开发项目过程中,经常需要定时任务来帮助我们来做一些内容, Spring Boot 默认已经帮我们实行了,只需要添加相应的注解就可以实现 1.pom 包配置 pom 包里面只需要引入 Spring ...
- [树组BIT]训练两题重新理解ver.
树状数组重(jiao)新(wo)理(zuo)解(ren) POJ-2352 加加加都给我加 输入是一行一行按照x从小到大给出的,所以对于每个点,要考虑的只是x比它小的点的个数.即记录各个x的情况,并且 ...
- Oracle 11g ogg单表初始化步骤
ogg单表初始化步骤 2018-06-08 14:55 296 0 原创 GoldenGate 本文链接:https://www.cndba.cn/leo1990/article/2842 1.ogg ...
- mysql 查询时指定校对规则
为了能在查询时忽略字段大小写,又不想修改数据表的属性配置,就在SQL语句中做了修改.结果在alibaba druid 执行时报错 com.alibaba.druid.sql.parser.Parser ...
- CodeForces - 1040B Shashlik Cooking(水题)
题目: B. Shashlik Cooking time limit per test 1 second memory limit per test 512 megabytes input stand ...
- Java判断当前时间是否在某一时间段内
今天有一个任务,判断现在的时间是否在某一个时间段内 遇到的第一个问题 Date类获取日期时间大的方法失效了 问题描述: 在学习Date类时,习惯性的用get方法调用Date()的年月日,发现不怎么好用 ...
- redis应用-分布式锁
一个操作要修改用户的状态,修改状态需要先读出用户的状态,在内存里进行修改,改完了再存回去.如果这样的操作同时进行了,就会出现并发问题,因为读取和保存状态这两个操作不是原子的. set lock:cod ...