gpt4 book ai didi

java.sql.SQLException : No suitable driver found in Netbeans

转载 作者:行者123 更新时间:2023-11-29 23:17:03 25 4
gpt4 key购买 nike

我在一个类中有这段代码用于连接数据库。

package fullhouse;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

public class FullhouseDB {

private static Connection databaseConnectie;


public static Connection getConnection() {
if(databaseConnectie == null){
String connectString = "jdbc:mysql://localhost:3306/fullhouse";
try {
databaseConnectie = DriverManager.getConnection(connectString, "root", "2002112735");
} catch (SQLException ex) {
Logger.getLogger(FullhouseDB.class.getName()).log(Level.SEVERE, null, ex);
}
}

return databaseConnectie;

}

我收到此错误:

dec 29, 2014 5:05:49 PM fullhouse.FullhouseDB getConnection
SEVERE: null
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/fullhouse

我检查了用户名和密码、数据库服务的连接,一切正确。

最佳答案

您需要使用以下方式加载驱动程序类:

Class.forName("com.mysql.jdbc.Driver");

然后定义连接字符串 url。

String connectString = "jdbc:mysql://localhost:3306/fullhouse";

关于java.sql.SQLException : No suitable driver found in Netbeans,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27692338/

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