Kettle 学习之问题处理(一):连接数据库报错
不废话,直接讲解!
报错信息
光是看到这么多信息头就痛了,不过还是要给出来的,便于确实地分析问题。
错误连接数据库 [127.0.0.1] : org.pentaho.di.core.exception.KettleDatabaseException:
Error occurred while trying to connect to the database
Error connecting to database: (using class net.sourceforge.jtds.jdbc.Driver)
Network error IOException: Connection refused: connect
org.pentaho.di.core.exception.KettleDatabaseException:
Error occurred while trying to connect to the database
Error connecting to database: (using class net.sourceforge.jtds.jdbc.Driver)
Network error IOException: Connection refused: connect
at org.pentaho.di.core.database.Database.normalConnect(Database.java:493)
at org.pentaho.di.core.database.Database.connect(Database.java:389)
at org.pentaho.di.core.database.Database.connect(Database.java:360)
at org.pentaho.di.core.database.Database.connect(Database.java:350)
at org.pentaho.di.core.database.DatabaseFactory.getConnectionTestReport(DatabaseFactory.java:83)
at org.pentaho.di.core.database.DatabaseFactory.getConnectionTestResults(DatabaseFactory.java:112)
at org.pentaho.di.core.database.DatabaseMeta.testConnectionSuccess(DatabaseMeta.java:2848)
at org.pentaho.ui.database.event.DataHandler.testDatabaseConnection(DataHandler.java:649)
at sun.reflect.GeneratedMethodAccessor93.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.pentaho.ui.xul.impl.AbstractXulDomContainer.invoke(AbstractXulDomContainer.java:313)
at org.pentaho.ui.xul.impl.AbstractXulComponent.invoke(AbstractXulComponent.java:157)
at org.pentaho.ui.xul.impl.AbstractXulComponent.invoke(AbstractXulComponent.java:141)
at org.pentaho.ui.xul.swt.tags.SwtButton.access$500(SwtButton.java:43)
at org.pentaho.ui.xul.swt.tags.SwtButton$4.widgetSelected(SwtButton.java:137)
at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.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.di.ui.xul.KettleDialog.show(KettleDialog.java:89)
at org.pentaho.di.ui.xul.KettleDialog.show(KettleDialog.java:56)
at org.pentaho.di.ui.core.database.dialog.XulDatabaseDialog.open(XulDatabaseDialog.java:117)
at org.pentaho.di.ui.core.database.dialog.DatabaseDialog.open(DatabaseDialog.java:61)
at org.pentaho.di.ui.spoon.delegates.SpoonDBDelegate.editConnection(SpoonDBDelegate.java:96)
at org.pentaho.di.ui.spoon.Spoon.doubleClickedInTree(Spoon.java:3140)
at org.pentaho.di.ui.spoon.Spoon.doubleClickedInTree(Spoon.java:3075)
at org.pentaho.di.ui.spoon.Spoon.access$1700(Spoon.java:373)
at org.pentaho.di.ui.spoon.Spoon$26.widgetDefaultSelected(Spoon.java:6354)
at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.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:1385)
at org.pentaho.di.ui.spoon.Spoon.waitForDispose(Spoon.java:7968)
at org.pentaho.di.ui.spoon.Spoon.start(Spoon.java:9350)
at org.pentaho.di.ui.spoon.Spoon.main(Spoon.java:711)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.pentaho.commons.launcher.Launcher.main(Launcher.java:92)
Caused by: org.pentaho.di.core.exception.KettleDatabaseException:
Error connecting to database: (using class net.sourceforge.jtds.jdbc.Driver)
Network error IOException: Connection refused: connect
at org.pentaho.di.core.database.Database.connectUsingClass(Database.java:601)
at org.pentaho.di.core.database.Database.normalConnect(Database.java:477)
... 47 more
Caused by: java.sql.SQLException: Network error IOException: Connection refused: connect
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:436)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.pentaho.di.core.database.Database.connectUsingClass(Database.java:585)
... 48 more
Caused by: java.net.ConnectException: Connection refused: 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 net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:288)
at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:251)
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:331)
... 52 more
主机名 : 127.0.0.1
端口 : 1433
数据库名:UFDATA_003_2021
问题解析
以上错误提示太多,真正用于分析的可从以下语句进行:
错误连接数据库 [127.0.0.1] : org.pentaho.di.core.exception.KettleDatabaseException:
Error occurred while trying to connect to the database
Error connecting to database: (using class net.sourceforge.jtds.jdbc.Driver)
Network error IOException: Connection refused: connect
这里的大概意思其实就是:在尝试连接数据库时发生了错误,连接不成功,使用net.sourceforge.jtds.jdbc.Driver类连接被拒绝。
出现这样子的情况,有以下原因:
1、连接参数设置错误。
这个我遇到过,因为数据库默认是1433的端口号,导致我一直连接错误,所以连接时最好检查下。
2、jar包错误。
此错误也是大多数人遇到的问题,lib目录缺少了对应数据库的驱动程序,导致连接时无法识别到数据库,就报错了。
问题处理过程
了解了错误的原因,那基本就好解决了。
处理1:连接参数设置错误
这个处理起来就比较简单了,对照着各个参数设置即可。
- 主机名直接填网络内的数据服务器的主机名称或者是IP都可以,使用主机名更方便。
- 数据库名称就是所需要连接的数据库的名称。
- 端口号算是最需要,因为默认的1433可能会被占用,那就需要去确认正确的端口号了。
- 用户名跟密码就填写登录数据库的用户名跟密码,可以使用sa,但在做项目的时候最好还是不要,自己建立一个用来连接即可。
以下讲解如何确认数据库的端口号
确认数据库的端口设置
如需确认数据库端口,则进入数据库中,新建查询,输入以下语句查询:
exec sys.sp_readerrorlog 0, 1, 'listening'
直接执行语句,就能够在查询到的表中获得端口信息了
修改端口的设置
知道了数据库的端口号,就直接在Kettle中进行修改即可,修改完成后再次测试,问题迎刃而解。
处理2:jar包错误
jar包的问题就需要下载驱动程序文件用以补充lib。
下载驱动程序
需要下载的是jtds驱动程序,不同的数据库有不同的包,以下提供下载地址。
- SQL Server驱动程序下载地址:https://sourceforge.net/projects/jtds/
- MySQL驱动程序下载地址:https://dev.mysql.com/downloads/connector/j/
下载完成后,将jar包放到kettle程序的lib文件夹下即可。
注意:本文有参考部分网文,自身实践总结得出的结果,旨在学习积累,如有异议还请指出,会酌情借鉴进行修改,感谢各路大佬的文章指导。