一,我用的数据库访问错误
### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Cannot create PoolableConnectionFactory (Communications link failure
The last packet successfully received from the server was 19,126 milliseconds ago. The last packet sent successfully to the server was 19,126 milliseconds ago.)
### The error may exist in file [D:\software\apache-tomcat-7.0.70\webapps\ROOT\WEB-INF\classes\com.hcmony.mapper\UserMapper.xml]
### The error may involve com.hcmony.mapper.UserMapper.findById
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Cannot create PoolableConnectionFactory (Communications link failure
The last packet successfully received from the server was 19,126 milliseconds ago. The last packet sent successfully to the server was 19,126 milliseconds ago.)] with root cause
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Cannot create PoolableConnectionFactory (Communications link failure The last packet successfully received from the server was 19,120 milliseconds ago. The last packet sent successfully to the server was 19,119 milliseconds ago.) ### The error may exist in file [D:\software\apache-tomcat-7.0.70\webapps\ROOT\WEB-INF\classes\com.hcmony.mapper\UserMapper.xml] ### The error may involve com.hcmony.mapper.UserMapper.findById ### The error occurred while executing a query ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Cannot create PoolableConnectionFactory (Communications link failure The last packet successfully received from the server was 19,120 milliseconds ago. The last packet sent successfully to the server was 19,119 milliseconds ago.) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:980) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:859) javax.servlet.http.HttpServlet.service(HttpServlet.java:624) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:844) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
root cause
主要问题有几个:
1,配置文件写错,比如是某个字母写错了,或者漏掉了,
如<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
写成<property name="driverClassName" value="com.mysql.jdbc.Drivar"/>之类的,
还有其它url,用户名,密码之类的,多找找。
2,网络不通导致的.因为是在远程需要vpn. 碰到此问题可以先检查下网络
我碰到的就这个问题,换成本地就好了。
3,缺少jar包导致的。
<!-- 导入Mysql数据库链接jar包 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.36</version> </dependency><!-- 导入dbcp2的jar包,用来在applicationContext.xml中配置数据库 --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-dbcp2</artifactId> <version>2.1.1</version> </dependency>