Matthew
Matthew

Reputation: 818

Why isn't this Python JDBC connection working?

I'm trying to connect to a sybase type DB via the jaydebeapi, but I'm running into problems. I'm getting a strange error when I try to connect and I can't figure out why... Here is the code:

import jaydebeapi
conn = jaydebeapi.connect('net.sourceforge.jtds.jdbc.Driver', ['jdbc:jtds:sybase://hostname:port/database','username','password'],['/home/homedirectory/jtds-1.2.5-dist/jtds-1.2.5.jar'])

Here is the error produced:

Traceback (most recent call last):
  File "testos.py", line 3, in <module>
    conn = jaydebeapi.connect('net.sourceforge.jtds.jdbc.Driver', ['jdbc:jtds:sybase://hostname:port/','username','password'],['/home/homedirectory/jtds-1.2.5-dist/jtds-1.2.5.jar'])
  File "/usr/lib/python2.6/site-packages/JayDeBeApi-0.2.0-py2.6.egg/jaydebeapi/__init__.py", line 359, in connect
    jconn = _jdbc_connect(jclassname, jars, libs, *driver_args)
  File "/usr/lib/python2.6/site-packages/JayDeBeApi-0.2.0-py2.6.egg/jaydebeapi/__init__.py", line 183, in _jdbc_connect_jpype
    return jpype.java.sql.DriverManager.getConnection(*driver_args)
jpype._jexception.SQLExceptionPyRaisable: java.sql.SQLException: The executeQuery method must return a result set.

Why am I getting this error?

Upvotes: 1

Views: 2938

Answers (2)

Matthew
Matthew

Reputation: 818

I found that using the "net.sourceforge.jtds.jdbc.Driver" (jtds.jar) just wasn't working for me. When I switched to "com.sybase.jdbc4.jdbc.SybDriver" (jconn4.jar), it started working perfectly. Both drivers are supposed to work, so I assume it's a bug in the net.sourceforge.jtds.jdbc.Driver

Upvotes: 1

NendoTaka
NendoTaka

Reputation: 1224

This means that you are probably calling the executeQuery function incorrectly or with the wrong type of sql. Try using execute instead of executeQuery.

Note: This assumes that there is a call to executeQuery that you did not post in you question while still being in your code.

Upvotes: 1

Related Questions