-
Notifications
You must be signed in to change notification settings - Fork 78
Error - using a postgres database - NameError: Error fill report: Erro fill internal: java.lang.NullPointerException #161
Description
The documentation on how to connect to a DB is COMPLETELY wrong.
»This document is written and tested for pyreportjasper version 2.1.3«
Here is how I did with a bit of explanation: you need 3 different keys in the db_connection dict required by the PyReportJasper.config() method:
driver: the correct value for the PostgreSQL database is postgres; you can find the values in the pyreportjasper/db.py -> DB.get_connection() method (the dbtype string in the "if" chain)
jdbc_driver: it's the full path up to and including the jdbc directory provided with the pyreportjasper library; the easiest way to find it in your case is the following python script:
import sys
import pathlib
from pyreportjasper import PyReportJasper # <-- you probably have this line in yout code
print(str(pathlib.Path(sys.modules[PyReportJasper.__module__].__file__).parent / "libs" / "jdbc"))
jdbc_dir: the correct value for the PostgreSQL database is org.postgresql.Driver; this was the trickiest value to find out, I used the following BASh script, that can be useful if you want to use the other undocumented jdbc drivers:
# The value of the JDBC_DIR variable is the path you found with the previous python script
JDBC_DIR=/venv/py3.8.18/lib/python3.8/site-packages/pyreportjasper/libs/jdbc
basename $(strings ${JDBC_DIR}/postgresql.jar | grep -P 'Driver.class$' | sed 's#/#.#g') .class
Note the schema key is mandatory, but meaningless for PostgreSQL; set it to the very same value you are using for the database key.
Finally a recap:
self._jasper_db_parameters=JasperDBParameters(
jdbc_driver='org.postgresql.Driver',
jdbc_dir='/venv/py3.8.18/lib/python3.8/site-packages/pyreportjasper/libs/jdbc',
driver='postgres',
host='....',
port='....',
username='....',
password='....',
schema='....', # <-- same value you used for the database parameter
database='....')