<分区>
当我尝试连接到数据库进行查询时,发生异常。 “SQL 异常:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:数据源拒绝建立连接,来自服务器的消息:“连接太多”
public class DBConnection {
public static java.sql.Connection connect() throws ClassNotFoundException {
Connection con = null;
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/dmr";
String username = "root";
String password = "root";
try {
// Establishing connection
con = DriverManager.getConnection(url,username,password);
}
catch (SQLException ex) {
System.out.println("SQL Exception : "+ ex);
}
if(con != null){
System.out.println("****CONNECT TO THE DATABASE*****");
}
else{
System.out.println("####NOT CONNECT TO THE DATABASE");
}
return con;
}
}