这是我的jdbc属性(使用com.mchange.v2.c3p0.ComboPooledDataSource
):
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://myserveraddress:3306/mydatabasename?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false
jdbc.username=myusername
jdbc.password=mypassword
当myserveraddress
为localhost
或my local ip address
时,一切正常:)
但是,当myserveraddress
为my server ip address
(局域网外)时,会出现例外情况:(
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
Caused by: java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
Caused by: com.mchange.v2.resourcepool.TimeoutException: A client timed out while waiting to acquire a resource from com.mchange.v2.resourcepool.BasicResourcePool@6c4f5d64 -- timeout at awaitAvailable()
实际上,我已经通过cmd,HeidiSQL,IntelliJ IDEA测试了服务器地址,一切正常......
cmd ping and cmd mysql connection is ok
HeidiSQL connection and IntelliJ IDEA mysql connection test is ok
感到困惑,感谢您的帮助
答案 0 :(得分:0)
首先检查您的端口(3306)是否已在此网页http://portchecker.co/上打开(从外部,路由器可能会阻止您的端口接收传入连接),如果没有:
- 在路由器上进行端口转发
OR
- 将您的服务器放到路由器上的DMZ