JDBC — java.lang.NoClassDefFoundError: Could not initialize class com.mysql.jdbc.Connection

不问归期 提交于 2019-12-01 14:31:34
jjathman

This is almost certainly because you are missing the jdbc driver jar for MySql. You can find it Here. Unzip it and add the jar to your classpath.

Update: You can not use MySQL with GAE because sockets are not allowed. This will never work for you. They have alternative persistence mechanisms besides MySQL. See: Can I use a MySQL database with an App Engine application

Try this:

try
{   // Load driver class
    Class.forName("com.mysql.jdbc.Driver");
}
catch (java.lang.ClassNotFoundException e) {
    System.err.println("ClassNotFoundException: " +e);
}

Instead of:

 try {
    // Exception thrown in next line.
        Class.forName(driver).newInstance();
        conn = DriverManager.getConnection(url, userName, password);
    } catch (Exception e) {
        return null;
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!