I'm trying to connect to a MMSQL Database through python in a Jupyter environment with the addition of a JDBC Driver. Although everything should be set up in a correct manner the Error Message "TypeError: Class com.microsoft.sqlserver.jdbc.SQLServerDriver is not found" keeps reappearing everytime I run this code. The Paths should be set up corectly, the JAVA_HOME Variable aswell and the packages should work on Mac(M1). A friend of mine tested it on her windows notebook (also in a jupyter notebook file) and it worked for her without running into this error.
- JDBC Driver: mssql-jdbc-12.8.1.jre11.jar
- JDK version: "21.0.5"
- Mac version: MacOS Sonoma (Version 14.5)
- Python version: 3.11.5 Please let me know if there is any additional information that could be helpful!
import os import jpype import jaydebeapi import pandas as pd # Pfad zur JAR-Datei jdbc_driver_path = 'path/to/jar/file' if not os.path.isfile(jdbc_driver_path): print(f"JAR-Datei wurde nicht gefunden unter: {jdbc_driver_path}") else: print(f"JAR-Datei ist vorhanden: {jdbc_driver_path}") # Start JVM mit der JAR-Datei im Klassenpfad if not jpype.isJVMStarted(): jpype.startJVM(jpype.getDefaultJVMPath(), f"-Djava.class.path={jdbc_driver_path}") # Verbindungsparameter server = 'dwh...' database = 'db_name' username = 'username' password = 'password' # JDBC-URL jdbc_url = f'jdbc:sqlserver://{server};databaseName={database};encrypt=true;trustServerCertificate=true' # Verbindung zur Datenbank herstellen try: conn = jaydebeapi.connect( 'com.microsoft.sqlserver.jdbc.SQLServerDriver', jdbc_url, [username, password], jars=jdbc_driver_path ) print("Verbindung erfolgreich hergestellt") # Cursor erstellen cursor = conn.cursor() # Tabelle für Abfrage table_name = 'Facts_Monthly_Sales_Quota' # SQL-Abfrage zum Abrufen aller Daten der Tabelle query = f"SELECT * FROM {table_name}" # Abfrage ausführen und Ergebnisse in eine Liste laden cursor.execute(query) data = cursor.fetchall() columns = [desc[0] for desc in cursor.description] # DataFrame erstellen df = pd.DataFrame(data, columns=columns) # DataFrame anzeigen print(df) # Verbindung und Cursor schließen cursor.close() conn.close() except Exception as e: import traceback print("Fehler beim Herstellen der Verbindung:") traceback.print_exc() # Zeigt den vollständigen Stacktrace an Any help would be greatly appreciated!
I tried to set up a database connection to access the data, it should connect but it keeps running into the same error. Complete Output