用idea连接mysql时,出现.NullPointerException异常
connection 返回值为 null
package com.atstudy.utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBUtils {
private static final String MYSQL_URL = "jdbc:mysql://localhost:3306/29db";
private static final String MYSQL_USER = "root";
private static final String MYSQL_PASSWORD = "123456";
private static Connection connection = null;
//静态代码块(随着类的加载而执行一次)
static {
try {
connection = DriverManager.getConnection(MYSQL_URL, MYSQL_USER, MYSQL_PASSWORD);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
public static Connection getConn(){
return connection;
}
}
异常