NutzCN Logo
问答 链接数据库的时候,创建的dao,但是当 数据库信息不正确的时候,在new NutDao的时候,会报下面的异常,我写了try catch 无法捕获,还麻烦老师,指导一下,怎么解决捕获这个问题.
发布于 2600天前 作者 qq_e86802e0 2056 次浏览 复制 上一个帖子 下一个帖子
标签:
DruidDataSource dsLog = DbConfigUtil.getInstance().getDataSource(log,
						false);
				Dao daoLog = new NutDao(dsLog);

上面是我链接数据库的时候,创建的dao,但是当
数据库信息不正确的时候,在new NutDao的时候,会报下面的异常,我写了try catch 无法捕获,还麻烦老师,指导一下,怎么解决这个问题.

2017-10-10 11:07:24,858 com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:1890) ERROR - create connection error, url: jdbc:mysql://10.66.194.55:3306/fml_game_log_1_5
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
	at sun.reflect.GeneratedConstructorAccessor50.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
	at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1036)
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:338)
	at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2232)
	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2265)
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2064)
	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:790)
	at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
	at sun.reflect.GeneratedConstructorAccessor48.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:395)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1375)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1431)
	at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:1888)
Caused by: java.net.ConnectException: Connection timed out: connect
	at java.net.DualStackPlainSocketImpl.connect0(Native Method)
	at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
	at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
	at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
	at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
	at java.net.PlainSocketImpl.connect(Unknown Source)
	at java.net.SocksSocketImpl.connect(Unknown Source)
	at java.net.Socket.connect(Unknown Source)
	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:213)
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:297)
	... 14 more
4 回复
try {

} catch (Throwable e) { // 这样肯定能catch到

}

我试了,还是无法捕获,


try{ Dao daoLog = new NutDao(dsLog); }catch(Throwable e){ }

是这一句抛异常,不是new NutDao的时候

DruidDataSource dsLog = DbConfigUtil.getInstance().getDataSource(log, false);

具体还是看报错堆栈吧

添加回复
请先登陆
回到顶部