Hey ya’ll,
This will sound like a strange situation.
So I made a StreamLit app where it makes a database connection to a DB2 server, submits a query, and then just simply displays the query result as a pandas dataframe. I am using jaydebeapi library. When I first launch the StreamLit server, my StreamLit app displays the dataframe fine, no errors…all fine and dandy.
But here’s the weird part. If I hit the browser refresh button or if it refreshed after the first initial load, I get a jaydebeapi specific error. If I restart the server, it refreshes, and then everything is fine!? But, if it refreshes after than initial load, boom, get an error message all over again.
I also executed a non-StreamLit version in an ipython session, multiple times, and get no/ZERO errors. So it is something weird on StreamLit side where it is not saving state or session and somehow causing my jaydebeapi error.
Here’s the error message (some info scrubbed):
java.sql.SQLExceptionPyRaisable: java.sql.SQLException: No suitable driver found for jdbc:db2://some_server:50000/some_database
File “c:\users\user\appdata\local\continuum\anaconda3_64bit\envs\dashboards\lib\site-packages\streamlit\ScriptRunner.py”, line 306, in run_script exec(code, module.dict)
File “D:\pyscripts\streamlit\defect_rates.py”, line 17, in jars=[‘D:/JDBC_Drivers/folder1/db2jcc4.jar’, ‘D:/JDBC_Drivers/folder1/db2jcc.jar’])
File "c:\users\user\appdata\local\continuum\anaconda3_64bit\envs\dashboards\lib\site-packages\jaydebeapi_init.py", line 381, in connect jconn = jdbc_connect(jclassname, url, driver_args, jars, libs)
File "c:\users\user\appdata\local\continuum\anaconda3_64bit\envs\dashboards\lib\site-packages\jaydebeapi_init.py", line 199, in _jdbc_connect_jpype return jpype.java.sql.DriverManager.getConnection(url, *dargs)
Here’s my StreamLit app code:
from getpass import getpass
import jaydebeapi as jdba
import os
import pandas as pd
import streamlit as st
‘’’
Web App to Obtain Some Data
‘’’
user = os.environ[‘some_user_var’]
pwd = os.environ[‘some_pwd_var’]
conn = jdba.connect(‘com.ibm.db2.jcc.DB2Driver’, ‘jdbc:db2://some_server:50000/some_database’,
[user, pwd],
jars=[‘D:/JDBC_Drivers/folder1/db2jcc4.jar’, ‘D:/JDBC_Drivers/folder1/db2jcc.jar’])
sql = “”"
SELECT
*
FROM
some_table
FETCH FIRST 200 ROWS ONLY
“”"
df = pd.read_sql(sql, conn, index_col=None)
conn.close()
st.write(df)
I can execute the above script excluding the last line in an ipython session multiple times and get no errors at all.