简体   繁体   English

java.lang.RuntimeException: Class com.mysql.cj.jdbc.Driver not found

[英]java.lang.RuntimeException: Class com.mysql.cj.jdbc.Driver not found

I have this conection to MySql in python with JayDeBeApi, using JDBC:我使用 JayDeBeApi 与 python 中的 MySql 有此连接,使用 JDBC:

def data_JDBC(db_name, table, db, user, pwd):
    
    db = db.lower()
    db_name = db_name.lower()
    print(db)
    if db == 'postgresql':
        sql_str = f"select * from {db}.{table}"
        host='ec2-18-191-149-107.us-east-2.compute.amazonaws.com'
        port='5432'
        user=user
        pwd = pwd
        driver_name = 'org.postgresql.Driver'
        driver_path = 'path/to/postgresql-42.2.12.jar'        
    elif db == 'mysql':
        sql_str = f"select * from {table}"
        host='localhost'
        port='3306'
        user=user
        pwd = ""
        driver_name = 'com.mysql.cj.jdbc.Driver'
        driver_path = 'path/to/mysql-connector-java-8.0.20.jar'
        print(driver_path)
    connection_string=f'jdbc:{db}://'+ host+':'+ port +'/'+ db_name+'?useSSL=false&&serverTimezone=UTC&useLegacyDatetimeCode=false'
    if jpype.isJVMStarted() and not jpype.isThreadAttachedToJVM():
        jpype.attachThreadToJVM()
        jpype.java.lang.Thread.currentThread().setContextClassLoader(jpype.java.lang.ClassLoader.getSystemClassLoader())
    conn = jaydebeapi.connect(driver_name, connection_string,[user, pwd], jars=driver_path)
    frame = pd.read_sql(sql_str, conn);
    pd.set_option('display.expand_frame_repr', False)
    conn.close()
    return frame

This function returns a Pandas DataFrame, i have the jar files in the same directory.这个 function 返回一个 Pandas DataFrame,我在同一个目录中有 Z68995FCBF432492D15484D04A9D2 文件。 PostgreSQL works fine, but when i select for MySQL i get this error: PostgreSQL 工作正常,但是当我 select 为 MySQL 我得到这个错误:

java.lang.RuntimeExceptionPyRaisable      Traceback (most recent call last)
<ipython-input-426-311d4ecabc53> in <module>
----> 1 dfMysql=data_JDBC(db_name='fuentedatos', table='tests', db='MySql', user='root', pwd='')
      2 dfMysql

...

java.lang.RuntimeExceptionPyRaisable: java.lang.RuntimeException: Class com.mysql.cj.jdbc.Driver not found

This is how i execute the function:这就是我执行 function 的方式:

data_JDBC(db_name='fuentedatos', table='tests', db='MySql', user='root', pwd='')

For that particular error case there are two potential error causes.对于那个特定的错误情况,有两个潜在的错误原因。

1- Usually in the Java world the java.lang.RuntimeException: Class driverClassName not found exception is raised when we hadn't add the jar file's path to the CLASSPATH environment variable and that's what was exactly attempted to be explained here 1- Usually in the Java world the java.lang.RuntimeException: Class driverClassName not found exception is raised when we hadn't add the jar file's path to the CLASSPATH environment variable and that's what was exactly attempted to be explained here

2- (the most likely one) It seems like Jaydebeapi doesn't support the establishment of multiple connections for different data sources at the same time ( github issue ). 2-(最有可能的)Jaydebeapi似乎不支持同时为不同的数据源建立多个连接( github问题)。

I encountered this issue because I accidentally used 2 containers at the same time, plase make sure only one container is active to open the local directory.我遇到这个问题是因为我不小心同时使用了 2 个容器,请确保只有一个容器处于活动状态才能打开本地目录。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.RuntimeExceptionPyRaisable:java.lang.RuntimeException:找不到类com.teradata.jdbc.TeraDriver - java.lang.RuntimeExceptionPyRaisable: java.lang.RuntimeException: Class com.teradata.jdbc.TeraDriver not found 从数据块连接到数据库时获取 java.lang.ClassNotFoundException: com.mysql.jdbc.Driver - Getting java.lang.ClassNotFoundException: com.mysql.jdbc.Driver when connecting to db from databricks java.lang.ClassNotFoundException: com.mysql.Z84BEFFD3A0D49636A58ZZDriver在Amazon ECAterAbook877中 - java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Jupyter Notebook on Amazon EMR Jupyter Spark数据库访问; java.lang.ClassNotFoundException:com.mysql.jdbc.Driver - Jupyter Spark database access; java.lang.ClassNotFoundException: com.mysql.jdbc.Driver python-java.lang.Exception:找不到类oracle.jdbc.driver.OracleDriver - python - java.lang.Exception: Class oracle.jdbc.driver.OracleDriver not found pyspark错误:java.lang.RuntimeException:[1.18]错误:预期的标识符 - pyspark error :java.lang.RuntimeException: [1.18] failure: identifier expected Hadoop:错误:java.lang.RuntimeException:配置对象时出错 - Hadoop: Error: java.lang.RuntimeException: Error in configuring object 如何使用JPype捕获并显示java.lang.RuntimeException的stacktrace - How to catch and display stacktrace for java.lang.RuntimeException using JPype Hadoop Mapreduce 作业失败:java.lang.RuntimeException:配置 ZA8CFDE6331149EB2ACZ6FB89 时出错 - Hadoop Mapreduce Job failes :java.lang.RuntimeException: Error in configuring object Pycharm - 内部启动问题 -java.lang.RuntimeException:找不到安装主路径 - Pycharm - Internal Startup issue -java.lang.RuntimeException: Could not find installation home path
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM