无法使用MySQL驱动程序创建JDBC连接。面对“ com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException”

时间:2019-04-20 17:59:14

标签: mysql jdbc connection

无法使用MySQL驱动程序创建JDBC连接。面对

  

“ com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException”

这是我正在使用的Java代码

public static Connection getConnection() throws ClassNotFoundException, SQLException {
        Connection con = null;
        try {
            Class.forName(DRIVERNAME);
            con = DriverManager.getConnection(URL, USERNAME, PASSWORD);
        } catch (ClassNotFoundException e) {
            System.out.println("MySQLUtil | getConnection() | ClassNotFoundException | "+e.getMessage());
            e.printStackTrace();
        } catch (Exception e) {
            System.out.println("MySQLUtil | getConnection() | Exception | "+e.getMessage());
            e.printStackTrace();
        }
        return con;
    }

0 个答案:

没有答案