gpt4 book ai didi

java - 使用 jdbc 驱动程序连接到 MySQL

转载 作者:行者123 更新时间:2023-11-29 01:37:25 24 4
gpt4 key购买 nike

<分区>

我创建了一个名为 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);

它不会发送任何错误,也不会建立连接。我该怎么办?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com