簡體   English   中英

使用 Python 腳本導入數據庫

[英]importing database using Python script

我正在嘗試使用我創建的 Python 腳本從數據庫中提取一些表...

import jaydebeapi as jdbc
import pandas.io.sql as psql
import pandas
import getpass
import yaml
p = yaml.load(file("/Users/glassjawed/.TD"))
# Contains password
c = jdbc.connect('com.teradata.jdbc.TeraDriver'
,['jdbc:teradata://******.***.***.com','glassjawed',p]
,['~/terajdbc4.jar','~/tdgssconfig.jar'])

# read in the table we want
df = psql.read_sql('SELECT TOP 10 user_id FROM store_users',c)
print(pandas.DataFrame.head(df))
print(type(df))

但我遇到了以下錯誤。

  File "EPNconnect.py", line 11, in <module>
    ,['~/terajdbc4.jar','~/tdgssconfig.jar'])
  File "/usr/lib/python2.7/dist-packages/jaydebeapi/__init__.py", line 359, in connect
    jconn = _jdbc_connect(jclassname, jars, libs, *driver_args)
  File "/usr/lib/python2.7/dist-packages/jaydebeapi/__init__.py", line 182, in _jdbc_connect_jpype
    jpype.JClass(jclassname)
  File "/usr/lib/python2.7/dist-packages/JPype1-0.6.1-py2.7-linux-x86_64.egg/jpype/_jclass.py", line 55, in JClass
    raise _RUNTIMEEXCEPTION.PYEXC("Class %s not found" % name)
jpype._jexception.RuntimeExceptionPyRaisable: java.lang.RuntimeException: Class com.teradata.jdbc.TeraDriver not found

我安裝了最新的 jar 文件,但仍然出現此錯誤。 我不知道如何解決這個問題。 幫助?

使用 JayDeBeApi 時,我在文件名中使用 ~ 時遇到了一些悲傷的經歷。 嘗試使用絕對路徑,例如:

    c = jdbc.connect('com.teradata.jdbc.TeraDriver', ['jdbc:teradata://******.***.***.com','glassjawed',p]
,['/Users/myUserID/terajdbc4.jar', '/Users/myUserID/tdgssconfig.jar'])

除此之外,我非常喜歡在使用 Python 時使用 teradata 包(和 ODBC)而不是 JayDeBeApi(和 JDBC)。

請參考這個帖子

您需要獲取 Teradata JDBC 驅動程序並提供相應 jar 的正確路徑。 它應該工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM