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.