Trying to use Jaydebe to connect to a Teradata DB

Asked by dcsbeemer

Hi there

Apologies in advance if this has been asked before, but I'm trying to use JayDeBeApi to connect to a Teradata DB. The problem comes in where I seemingly require two .jar files at the same time, namely terajdbc4.jar and tdgssconfig.jar.

I've installed JayDeBe from source using Python 2.5 (32-bit Python on Windows 2008 R2 64-bit).

I'm not too sure if it's possible to specify multiple JAR files, and if it is, how to go about it exactly. The code I have so far (placed the JAR files in directory D:\TEST\TDJ:

import jaydebeapi
import jpype

def teradataconn():
    jar = r'D:\\TEST\\TDJ'
    args='-Djava.class.path=%s' % jar
    jvm_path = 'C:\\Program Files (x86)\\Java\\jre6\\bin\\java.exe'
    print jvm_path
    jpype.startJVM(jvm_path, args)

    conn = jaydebeapi.connect('com.teradata.jdbc.TeraDriver',
                            'jdbc:teradata://P1'
                           , 'tduser', 'tdpass')

    cursor = conn.cursor()

    cursor.execute("select * from test_table")
    rows = cursor.fetchall()

    for col1, col2 in rows:
        print str(col1)+", "+str(col2)

    conn.close()

    jpype.shutdownJVM()

if __name__ == '__main__':
    teradataconn()

I suspect that I might be having a problem with my Java initialization as well since I'm getting the following error when running:

Traceback (most recent call last):
  File "D:\TEST\DBTest.py", line 91, in <module>
    teradataconn()
  File "D:\TEST\DBTest.py", line 68, in teradatame
    jpype.startJVM(jvm_path, args)
  File "C:\Python25\Lib\site-packages\jpype\_core.py", line 44, in startJVM
    _jpype.startup(jvm, tuple(args), True)
RuntimeError: Unable to load symbol [JNI_CreateJavaVM], error = The specified procedure could not be found.

 at src/native/common/include\jp_platform_win32.h:69

I'm still busy checking if this is a problem with my Java settings, but just thought I'd ask regarding multiple JAR files as well to cover all the bases.

I suppose my questions are: Can multiple JAR files be specified, and if so, how more or less?

Thanks in advance.

Question information

Language:
English Edit question
Status:
Solved
For:
JayDeBeApi Edit question
Assignee:
No assignee Edit question
Solved by:
dcsbeemer
Solved:
Last query:
Last reply:
Revision history for this message
dcsbeemer (derick-smit) said :
#2

OK, seems we're in business. After googling around a bit more, seems like the best way to go about it is with the following:

import jaydebeapi
import jpype

def teradataconn():
    classpath = """D:\\TEST\\TDJ\\tdgssconfig.jar;D:\\TEST\\TDJ\\terajdbc4.jar"""
    jvm_path = jpype.getDefaultJVMPath()
    jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.class.path=%s" % classpath)

    conn = jaydebeapi.connect('com.teradata.jdbc.TeraDriver',
                            'jdbc:teradata://P1'
                           , 'tduser', 'tdpass')

    cursor = conn.cursor()

    cursor.execute("select * from test_table")
    rows = cursor.fetchall()

    for col1, col2 in rows:
        print str(col1)+", "+str(col2)

    conn.close()

    jpype.shutdownJVM()

if __name__ == '__main__':
    teradataconn()

Works like a charm now for the most part, except that the jpype.shutdownJVM() bit causes my Python to bomb out. That's totally unrelated to my original problem though.

Many thanks for this module btw, it's turning out to be a lifesaver.

Revision history for this message
Bastian (baztian) said :
#3

Thank you for reporting back the solution. I'm glad jaydebeapi is working against Teradata.

The first problem was you didn't specifiy the classpath correctly. The second problem was you've set the wrong path to your jvm.

Sorry but I can't help you with your jpype.shutdownJVM() problem as this is JPype related and I haven't had such a problem yet.

Revision history for this message
dcsbeemer (derick-smit) said :
#4

Thanks for the reply Bastian.

Apparently the jpype.shutdownJVM() issue is related to the version of Python I'm using (2.5). Completely agree though, this isn't related to JayDeBeApi at all. I'm not too sure it's anything fatal either so far, as the JVM seems to exit just fine once the Python script itself completes.

I can't tell you how long I've looked for a way to connect to Teradata DBs via Python. I'm running a 32-bit Python install on a 64-bit OS (long story), and it turns out getting Teradata ODBC drivers installed and picking up the correct ones via PyODBC is a bit of a nightmare. There's seemingly also no dedicated Python module for connecting to Teradata DBs.

 Now, instead of just getting a solution specifically for connecting to Teradata, your module seems more like a Swiss Army knife I can use for pretty much any type of DB that has a JDBC driver of some sort out there.

I'll stop now at the risk of sounding like an infomercial, but again, thanks for this. Definitely one of the best Python modules I've come across so far.