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("数据库繁忙,稍后再试");
    }
    }

  • 相关阅读:
    GitHub Interesting Collection
    使用 CSS3 Flexible Boxes 布局
    消失的属性
    浅谈 JavaScript 模块化编程
    为你的 Javascript 加点咖喱
    软件测试
    osi七层模型
    3_Hydra(爆破神器)
    2_NC(瑞士军刀)
    1_HTTP协议详解
  • 原文地址:https://www.cnblogs.com/hbym/p/15127408.html
Copyright © 2011-2022 走看看