我正在尝试使用jaydebeapi包连接到teradata数据库。
conn = jaydebeapi.connect('com.teradata.jdbc.TeraDriver',
['jdbc:teradata://ip/TMODE=ANSI,CHARSET=utf8', 'username', 'password'],
['/teradata/tdgssconfig.jar',
'/terajdbc4.jar'])
执行时出错:
TERAJDBC4 ERROR [main] com.teradata.jdbc.jdk6.JDK6_SQL_Connection@3d1a70a7 Connection to <ip_address> Wed Oct 07 13:47:29 IST 2015 socket orig=<ip_address> cid=22f79598 sess=0 java.net.SocketTimeoutException: connect timed out at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:579) at com.teradata.jdbc.jdbc_4.io.TDNetworkIOIF$ConnectThread.run(TDNetworkIOIF.java:1216)
Traceback (most recent call last):
File "test_teradata.py", line 32, in <module>
teradataconn()
File "test_teradata.py", line 26, in teradataconn
'/home/abhishek/git/dblore/code/lib/teradata/terajdbc4.jar'])
File "/usr/local/lib/python2.7/dist-packages/jaydebeapi/__init__.py", line 359, in connect
jconn = _jdbc_connect(jclassname, jars, libs, *driver_args)
File "/usr/local/lib/python2.7/dist-packages/jaydebeapi/__init__.py", line 183, in _jdbc_connect_jpype
return jpype.java.sql.DriverManager.getConnection(*driver_args)
jpype._jexception.SQLExceptionPyRaisable: java.sql.SQLException: [Teradata JDBC Driver] [TeraJDBC 15.00.00.20] [Error 1277] [SQLState 08S01] Login timeout for Connection to <ip_address> Wed Oct 07 13:47:29 IST 2015 socket orig=<ip_address> cid=22f79598 sess=0 java.net.SocketTimeoutException: connect timed out at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:579) at com.teradata.jdbc.jdbc_4.io.TDNetworkIOIF$ConnectThread.run(TDNetworkIOIF.java:1216)
答案 0 :(得分:2)
我使用以下代码连接到Teradata数据库,它可以与多个服务器和数据库配合使用。
import jaydebeapi
server=192.168.3.4
database=dbc
user=dbc
password=dbc
# from TD JDBC readme.txt
jclassname='com.teradata.jdbc.TeraDriver'
# from TD Studio jdbc:<subprotocol>://<server>:<port>/<database>
url='jdbc:teradata://'+server+'/'+database
# driver args contains the arguments passed to java: DriverManager.getConnections(...)
driver_args=[url,user,password]
# my jars are in CLASSPATH environment variable, if not then put the paths to them into a list, e.g.: jars=[r'C:\Program Files\Teradata\TeraJDBC\terajdbc4.jar;C:\Program Files\Teradata\TeraJDBC\tdgssconfig.jar']
jars=None
jaydebeapi.connect(jclassname,driver_args,jars)
与您的代码相比,我只在您的网址中看到ip(替换您的真实IP地址,我猜),您是否还在路径中添加了数据库名称?如果没有,问题可能就在那里。
答案 1 :(得分:0)
我遇到了类似的问题,下面有一个示例,希望对您有所帮助:
[root@myhost transfer]# cat test_conn.py
import jaydebeapi
from contextlib import closing
jclassname='com.teradata.jdbc.TeraDriver'
jdbc_driver_loc = '/opt/spark-2.3.1/jars/terajdbc4-16.20.00.06.jar,/opt/spark-2.3.1/jars/tdgssconfig-16.20.00.06.jar'
jdbc_driver_name = 'com.teradata.jdbc.TeraDriver'
host='my_teradata.address'
url='jdbc:teradata://' + host + '/TMODE=TERA'
login="teradata_user_name"
psw="teradata_passwd"
sql = "SELECT COUNT(*) FROM A_TERADATA_TABLE_NAME where month_key='202009'"
conn = jaydebeapi.connect(jclassname=jdbc_driver_name,
url=url,
driver_args=[login, psw],
jars=jdbc_driver_loc.split(","))
with closing(conn) as conn:
with closing(conn.cursor()) as cur:
cur.execute(sql)
print(cur.fetchall())
[root@myhost transfer]# python test_conn.py
[(7734133,)]
[root@myhost transfer]#