简体   繁体   English

使用 Python 脚本导入数据库

[英]importing database using Python script

I'm trying to extract some tables from a database using Python script I created...我正在尝试使用我创建的 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))

but I'm running into the following error.但我遇到了以下错误。

  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

I installed the latest jar files and I'm still getting this error.我安装了最新的 jar 文件,但仍然出现此错误。 I don't know how to work around this.我不知道如何解决这个问题。 Help?帮助?

When using JayDeBeApi I made some sad experience when using ~ in my filenames.使用 JayDeBeApi 时,我在文件名中使用 ~ 时遇到了一些悲伤的经历。 Try the absolut path instead, eg:尝试使用绝对路径,例如:

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

Beside this I'm a big fan of using teradata package (and ODBC) instead of JayDeBeApi (and JDBC) when using Python.除此之外,我非常喜欢在使用 Python 时使用 teradata 包(和 ODBC)而不是 JayDeBeApi(和 JDBC)。

Kindly refer to this post请参考这个帖子

You need to get Teradata JDBC drivers and give correct path of respective jars.您需要获取 Teradata JDBC 驱动程序并提供相应 jar 的正确路径。 It should work.它应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM