NutzCN Logo
问答 链接池链接异常捕捉不到
发布于 2930天前 作者 efraiser 2628 次浏览 复制 上一个帖子 下一个帖子
标签:

执行下面的方法,链接的地址不对时,就一直重复链接,无法捕捉异常返回空值。
public static DaoUp getNewConnect(String brNo) {
try {
SysEastUrlDao sysEastUrlDao = Mvcs.getIoc().get(SysEastUrlDao.class, "sysEastUrlDao");
SysEastUrl sysEastUrl = sysEastUrlDao.fetch(brNo);
if (sysEastUrl != null) {
DruidDataSource ds = new DruidDataSource();
ds.setDriverClassName(sysEastUrl.getDriver());
ds.setUrl(sysEastUrl.getUrlStr());
ds.setUsername(sysEastUrl.getUserName());
ds.setPassword(sysEastUrl.getPassword());
ds.getConnection();//在这报错
DaoUp daoUp = new DaoUp(brNo) {
};
daoUp.setDataSource(ds);
return daoUp;
} else {
return null;
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

报错信息:
create connection error, url: jdbc:db2://227.0.0.1:50000/sam
com.ibm.db2.jcc.am.yn: [jcc][t4][2043][11550][3.57.82] 异常 java.net.ConnectException:打开端口 50,000 上服务器 /227.0.0.1 的套接字时出错,消息为:connect: Address is invalid on local machine, or port is not valid on remote machine。 ERRORCODE=-4499, SQLSTATE=08001
at com.ibm.db2.jcc.am.bd.a(bd.java:319) ~[db2jcc.jar:na]
at com.ibm.db2.jcc.am.bd.a(bd.java:337) ~[db2jcc.jar:na]
at com.ibm.db2.jcc.t4.xb.a(xb.java:378) ~[db2jcc.jar:na]
at com.ibm.db2.jcc.t4.xb.(xb.java:76) ~[db2jcc.jar:na]
at com.ibm.db2.jcc.t4.a.y(a.java:263) ~[db2jcc.jar:na]
at com.ibm.db2.jcc.t4.b.a(b.java:1787) ~[db2jcc.jar:na]
at com.ibm.db2.jcc.am.jb.a(jb.java:540) ~[db2jcc.jar:na]
at com.ibm.db2.jcc.am.jb.(jb.java:496) ~[db2jcc.jar:na]
at com.ibm.db2.jcc.t4.b.(b.java:308) ~[db2jcc.jar:na]
at com.ibm.db2.jcc.DB2SimpleDataSource.getConnection(DB2SimpleDataSource.java:214) ~[db2jcc.jar:na]
at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:224) ~[db2jcc.jar:na]
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1386) ~[druid-1.0.16.jar:1.0.16]
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1442) ~[druid-1.0.16.jar:1.0.16]
at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:1881) ~[druid-1.0.16.jar:1.0.16]
Caused by: java.net.ConnectException: connect: Address is invalid on local machine, or port is not valid on remote machine
at java.net.DualStackPlainSocketImpl.connect0(Native Method) ~[na:1.7.0_10]
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69) ~[na:1.7.0_10]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) ~[na:1.7.0_10]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) ~[na:1.7.0_10]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) ~[na:1.7.0_10]
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157) ~[na:1.7.0_10]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391) ~[na:1.7.0_10]
at java.net.Socket.connect(Socket.java:579) ~[na:1.7.0_10]
at com.ibm.db2.jcc.t4.y.run(y.java:34) ~[db2jcc.jar:na]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.7.0_10]
at com.ibm.db2.jcc.t4.xb.a(xb.java:372) ~[db2jcc.jar:na]
... 11 common frames omitted

6 回复

getNewConnect 这是要调用N次的节奏?? 然后每次调用仅使用一次就扔掉?

@wendal 我要链接上远程的数据库执行操作,执行操作开始打开链接,操作结束关闭连接的。

那不要用druid,用SimpleDataSource

@wendal SimpleDataSource速度执行SQL的速度会慢吗?操作的数据条数有上千万条

@wendal 而且每一次操作要连续执行1000左右的SQL

如果用DaoUp+Druid,那么用完之后,必须调用close方法关闭DaoUp实例

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