今天接到用户的一个问题,业务厂商的应用程序无法连接某台DB2数据库。
和厂商的人沟通了之后,让他把连接报错的信息发过来看看,如下:
错误连接数据库 [EEE] : org.pentaho.di.core.exception.KettleDatabaseException:
Error occured while trying to connect to the database Error connecting to database: (using class com.ibm.db2.jcc.DB2Driver) [jcc][t4][2043][11550][3.50.152] 异常 java.net.ConnectException:打开端口 52,000 上服务器 /172.168.23.36 的套接字时出错,消息为:Connection timed out: connect。 ERRORCODE=-4499, SQLSTATE=08001 org.pentaho.di.core.exception.KettleDatabaseException: Error occured while trying to connect to the database Error connecting to database: (using class com.ibm.db2.jcc.DB2Driver) [jcc][t4][2043][11550][3.50.152] 异常 java.net.ConnectException:打开端口 52,000 上服务器 /172.168.23.36 的套接字时出错,消息为:Connection timed out: connect。 ERRORCODE=-4499, SQLSTATE=08001 at org.pentaho.di.core.database.Database.normalConnect(Database.java:312) at org.pentaho.di.core.database.Database.connect(Database.java:261) at org.pentaho.di.core.database.Database.connect(Database.java:223) at org.pentaho.di.core.database.Database.connect(Database.java:213) at org.pentaho.di.core.database.DatabaseFactory.getConnectionTestReport(DatabaseFactory.java:55) at org.pentaho.di.core.database.DatabaseMeta.testConnection(DatabaseMeta.java:2409) at org.pentaho.ui.database.event.DataHandler.testDatabaseConnection(DataHandler.java:487) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.pentaho.ui.xul.impl.AbstractXulDomContainer.invoke(AbstractXulDomContainer.java:294) at org.pentaho.ui.xul.impl.AbstractXulComponent.invoke(AbstractXulComponent.java:124) at org.pentaho.ui.xul.impl.AbstractXulComponent.invoke(AbstractXulComponent.java:112) at org.pentaho.ui.xul.swt.tags.SwtButton.access$000(SwtButton.java:17) at org.pentaho.ui.xul.swt.tags.SwtButton$1.widgetSelected(SwtButton.java:77) at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source) at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source) at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source) at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source) at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source) at org.eclipse.jface.window.Window.runEventLoop(Window.java:820) at org.eclipse.jface.window.Window.open(Window.java:796) at org.pentaho.ui.xul.swt.tags.SwtDialog.show(SwtDialog.java:238) at org.pentaho.di.ui.core.database.dialog.XulDatabaseDialog.open(XulDatabaseDialog.java:161) at org.pentaho.di.ui.spoon.delegates.SpoonDBDelegate.editConnection(SpoonDBDelegate.java:79) at org.pentaho.di.ui.spoon.Spoon.doubleClickedInTree(Spoon.java:2317) at org.pentaho.di.ui.spoon.Spoon.access$1600(Spoon.java:242) at org.pentaho.di.ui.spoon.Spoon$25.widgetDefaultSelected(Spoon.java:4061) at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source) at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source) at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source) at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source) at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source) at org.pentaho.di.ui.trans.steps.tableinput.TableInputDialog.open(TableInputDialog.java:378) at org.pentaho.di.ui.spoon.delegates.SpoonStepsDelegate.editStep(SpoonStepsDelegate.java:123) at org.pentaho.di.ui.spoon.Spoon.editStep(Spoon.java:6274) at org.pentaho.di.ui.spoon.trans.TransGraph.editStep(TransGraph.java:2296) at org.pentaho.di.ui.spoon.trans.TransGraph.access$100(TransGraph.java:150) at org.pentaho.di.ui.spoon.trans.TransGraph$6.mouseDoubleClick(TransGraph.java:454) at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source) at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source) at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source) at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source) at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source) at org.pentaho.di.ui.job.entries.sql.JobEntrySQLDialog.open(JobEntrySQLDialog.java:414) at org.pentaho.di.ui.spoon.delegates.SpoonJobDelegate.editJobEntry(SpoonJobDelegate.java:262) at org.pentaho.di.ui.spoon.Spoon.editJobEntry(Spoon.java:6169) at org.pentaho.di.ui.spoon.job.JobGraph.editEntry(JobGraph.java:2148) at org.pentaho.di.ui.spoon.job.JobGraph$6.mouseDoubleClick(JobGraph.java:381) at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source) at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source) at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source) at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source) at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source) at org.pentaho.di.ui.spoon.Spoon.readAndDispatch(Spoon.java:945) at org.pentaho.di.ui.spoon.Spoon.start(Spoon.java:5574) at org.pentaho.di.ui.spoon.Spoon.main(Spoon.java:412) Caused by: org.pentaho.di.core.exception.KettleDatabaseException: Error connecting to database: (using class com.ibm.db2.jcc.DB2Driver) [jcc][t4][2043][11550][3.50.152] 异常 java.net.ConnectException:打开端口 52,000 上服务器 /172.168.23.36 的套接字时出错,消息为:Connection timed out: connect。 ERRORCODE=-4499, SQLSTATE=08001 at org.pentaho.di.core.database.Database.connectUsingClass(Database.java:435) at org.pentaho.di.core.database.Database.normalConnect(Database.java:296) ... 57 more Caused by: com.ibm.db2.jcc.b.gm: [jcc][t4][2043][11550][3.50.152] 异常 java.net.ConnectException:打开端口 52,000 上服务器 /172.168.23.36 的套接字时出错,消息为:Connection timed out: connect。 ERRORCODE=-4499, SQLSTATE=08001 at com.ibm.db2.jcc.b.wc.a(wc.java:283) at com.ibm.db2.jcc.t4.xb.a(xb.java:354) at com.ibm.db2.jcc.t4.xb.<init>(xb.java:73) at com.ibm.db2.jcc.t4.a.w(a.java:260) at com.ibm.db2.jcc.t4.b.a(b.java:1775) at com.ibm.db2.jcc.b.eb.a(eb.java:452) at com.ibm.db2.jcc.b.eb.<init>(eb.java:417) at com.ibm.db2.jcc.t4.b.<init>(b.java:296) at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:193) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:185) at org.pentaho.di.core.database.Database.connectUsingClass(Database.java:416) ... 58 more Caused by: java.net.ConnectException: Connection timed out: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) at java.net.Socket.connect(Socket.java:519) at com.ibm.db2.jcc.t4.y.run(y.java:34) at java.security.AccessController.doPrivileged(Native Method) at com.ibm.db2.jcc.t4.xb.a(xb.java:348) ... 68 more 主机名 : 172.168.23.36 端口 : 52000 数据库名:DW_DB
一开始检查了DB2数据库没有问题,IP地址可以ping通,52000端口也处于监听状态,数据库名、用户名、密码都书写正确。应用程序连接其他的DB2都正常,唯独这个库无法访问。
根据报错信息,到IBM官网查了半天,没有找到原因。后来想到,是不是防火墙问题?于是telnet IP地址 52000端口,测试果然是不通的。原因就在这里,应该是防火墙策略屏蔽了本机IP网段,导致路由不通。 总结,这类问题的思路,首先应该想到最基本的可能原因,如:路由、端口等,telnet端口测试一下就知道了。