zoukankan      html  css  js  c++  java
  • java.lang.IllegalArgumentException: interface com.mysql.jdbc.JDBC4MySQLConnection is not visible from class loader

    Exception in thread "main" java.lang.ExceptionInInitializerError
    at szq.main.hbasetohive.HBaseReadTest.main(HBaseReadTest.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.spark.deploy.JavaMainApplication.start(SparkApplication.scala:52)
    at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:894)
    at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:198)
    at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:228)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:137)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
    Caused by: java.lang.IllegalArgumentException: interface com.mysql.jdbc.JDBC4MySQLConnection is not visible from class loader

    这个错误是连接mysql时候出现的
    主要问题: 在这里: conn.getClass().getInterfaces() 底下连接代码已经改正了正确方式
    /**
    * 获取数据库连接
    */
    public Connection getConnection() throws SQLException {
    if(connPool.size() > 0){
    //从集合中获取一个连接
    final Connection conn = connPool.removeFirst();
    //返回Connection的代理对象
    //这是错误的方式,获取接口的问题 conn.getClass().getInterfaces()
    // (Connection) Proxy.newProxyInstance(ConnPool.class.getClassLoader(), conn.getClass().getInterfaces(), new InvocationHandler() {
    //正确的方式 采用new Class[]{com.mysql.jdbc.Connection.class}的方式
    return (Connection) Proxy.newProxyInstance(ConnPool.class.getClassLoader(), new Class[]{com.mysql.jdbc.Connection.class}, new InvocationHandler() {
    public Object invoke(Object proxy, Method method, Object[] args)
    throws Throwable {
    if(!"close".equals(method.getName())){
    return method.invoke(conn, args);
    }else{
    connPool.add(conn);
    System.out.println("池中连接数为 " + connPool.size());
    return null;
    }
    }
    });
    }else{
    throw new RuntimeException("数据库繁忙,稍后再试");
    }
    }

  • 相关阅读:
    python--threading多线程总结
    云服务器 ECS Linux CentOS 修改内核引导顺序
    日记——心刊
    64位linux安装wine等软件
    service: no such service mysqld 与MySQL的开启,关闭和重启
    python调用chrome ie等浏览器
    Linux系统下强制踢掉登录用户
    python读取数据库数据,读取出的中文乱码问题
    jmeter生成时间的函数
    PHP 递归超过100次会自动停止
  • 原文地址:https://www.cnblogs.com/hbym/p/15127408.html
Copyright © 2011-2022 走看看