[英]java.sql.SQLException: No suitable driver found in Netbeans
I have this code in a class for the connection to the database. 我在用于连接数据库的类中具有此代码。
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;
}
And I get this error: 我得到这个错误:
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
I've checked the username and password, the connection of database services, and all is correct. 我已经检查了用户名和密码,数据库服务的连接,并且一切正确。
You need to load the driver class using: 您需要使用以下命令加载驱动程序类:
Class.forName("com.mysql.jdbc.Driver");
And then define connect string url. 然后定义连接字符串的URL。
String connectString = "jdbc:mysql://localhost:3306/fullhouse";
First you take mysql driver file from the url below url 首先,您从url下面的url中获取mysql驱动程序文件
http://projectshub.in/softwares/mysql/mysql-connector-java-5.0.8-bin.jar http://projectshub.in/softwares/mysql/mysql-connector-java-5.0.8-bin.jar
than add this driver file to your project lib folder. 将此驱动程序文件添加到您的项目lib文件夹中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.