Python Forum

Full Version: Unexpected termination of program when using JDBC drivers in python with jaydebeapi
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to connect to a solid DB using JDBC drivers and the program just prints "point - 0" and quits. I cannot do anything because the frustrating thing is it doesn't even raise exception so how can I understand what is wrong? If someone can at least guide me how to raise an exception it would be appreciated. Somehow the program is crashing in the connection.

import jaydebeapi

# Path to the Solid JDBC driver JAR file
jdbc_driver_jar = "C:\\Solid\\SolidDriver2.0.jar"

# JDBC URL for connecting to Solid
jdbc_url = "jdbc:solid://xxxxcorpdb03.corporate.intra:1865/SOLDBC"

# JDBC driver class name
jdbc_driver_class = "com.solid.jdbc.SolidDriver"

# Database username and password
username = "xxxx"
password = "xxx"

# Establishing the connection using JayDeBeApi
print('point - 0')
try:
    connection = jaydebeapi.connect(
    jdbc_driver_class,
    jdbc_url,
    [username, password],
    jdbc_driver_jar)
except Exception as e:
    raise e
finally:
    print ('finally')
  
print('point - 1')
cursor = connection.cursor()
print('point - 2')
cursor.execute("SELECT * FROM discount")
results = cursor.fetchall()
print(results)

cursor.close()
connection.close()
There's no reason for all of this:
try:
    connection = jaydebeapi.connect(
    jdbc_driver_class,
    jdbc_url,
    [username, password],
    jdbc_driver_jar)
except Exception as e:
    raise e
finally:
    print ('finally')
Leave out the try/except/finally, and if jaydebeapi.connect raises an exception, you will see the error message and the trace.

There are ill behaved packages that raise a SystemException (sys.exit(), exit(), quit()) when they run into an problem. You can catch those like this:
import sys
import traceback

try:
    # Replace sys.exit(1) with code you want to execute.
    sys.exit(1)
except SystemExit:
    print(traceback.format_exc())
Error:
Traceback (most recent call last): File "catchexittest.py", line 7, in <module> sys.exit(1) SystemExit: 1
Why are you using jaydebeapi (a python interface to a java interface to an oracle database) instead of python-oracledb, a package designed by oracle to be used with Python, or other Python/oracle database packages?
(Feb-16-2024, 07:22 PM)deanhystad Wrote: [ -> ]There's no reason for all of this:
try:
    connection = jaydebeapi.connect(
    jdbc_driver_class,
    jdbc_url,
    [username, password],
    jdbc_driver_jar)
except Exception as e:
    raise e
finally:
    print ('finally')
Leave out the try/except/finally, and if jaydebeapi.connect raises an exception, you will see the error message and the trace.

There are ill behaved packages that raise a SystemException (sys.exit(), exit(), quit()) when they run into an problem. You can catch those like this:
import sys
import traceback

try:
    # Replace sys.exit(1) with code you want to execute.
    sys.exit(1)
except SystemExit:
    print(traceback.format_exc())
Error:
Traceback (most recent call last): File "catchexittest.py", line 7, in <module> sys.exit(1) SystemExit: 1
Why are you using jaydebeapi (a python interface to a java interface to an oracle database) instead of python-oracledb, a package designed by oracle to be used with Python, or other Python/oracle database packages?


The reason I put the try/except/finally is to try and get some exception. I am using jaydebeapi because I want to connect to an IBM Solid DB with java drivers. The other option is ODBC drivers. I managed to get the ODBC drivers to work but they require more client config. Thanks a lot for your help so far, I will try the traceback and let you know! :)