Python Forum
Unexpected termination of program when using JDBC drivers in python with jaydebeapi
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unexpected termination of program when using JDBC drivers in python with jaydebeapi
#1
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()
deanhystad write Feb-16-2024, 06:56 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
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?
Reply
#3
(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! :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unexpected Output - Python Dataframes: Filtering based on Overlapping Dates Xensor 5 720 Nov-15-2023, 06:54 PM
Last Post: deanhystad
  PyQt5 MySQL Drivers Not Loaded AdeS 7 5,086 Aug-06-2021, 08:34 AM
Last Post: AdeS
  random behavriour when handle process termination signal in Python hamzeah 2 2,054 Jul-31-2019, 07:32 AM
Last Post: hamzeah
  lambda-Amazon EC2:Remove instance termination protection if enabled and terminate ins dragan979 0 3,367 Jun-13-2018, 09:48 AM
Last Post: dragan979
  IndentationError: unexpected indent (Python) segs 8 17,304 Aug-11-2017, 03:13 PM
Last Post: segs
  python to install printer drivers automatic leoxucn 4 7,688 Jul-10-2017, 09:21 PM
Last Post: Larz60+
  jaydebeapi architecture error? CraigBoyd 2 4,805 Feb-10-2017, 03:39 PM
Last Post: CraigBoyd

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020