【发布时间】:2016-09-07 17:22:39
【问题描述】:
我创建了一个名为 BD 的类,我在其中尝试与名为 bono 的数据库建立连接
public class BD {
String url,login,password,driver;
Connection conexion=null;
public BD(){
driver = "com.mysql.jdbc.Driver";
url = new String("jdbc:mysql://localhost:8000/bono");
login = new String("root");
password = new String("mypassword");
try {
Class.forName(driver);
conexion = DriverManager.getConnection(url, login, password);
System.out.println("Conexi�n con Base de datos Ok....");
} catch (ClassNotFoundException e) { //
System.out.println("error 1");
} catch (SQLException e) {
System.out.println("error 2");
}
}
但是当我执行它时,它只是停留在以下行中:
conexion = DriverManager.getConnection(url, login, password);
它不会发送任何错误,也不会建立连接。我该怎么办?
【问题讨论】:
-
测试,添加异常捕获块
-
或者干脆去掉端口部分,比如 jdbc:mysql://localhost/bono