您好,由于某种原因,我在课堂上遇到了编码问题。我正在尝试在数据库和 netbeans 之间进行连接,但不断收到标题中提到的错误
主要是这个类得到错误:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBHandler extends Configs {
Connection dbconnection;
public Connection getConnection()
{
String connectionString = "jdbc:mysql://"+ Configs.dbhost + ":" + Configs.dbport + "/" + Configs.dbname;
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
dbconnection = DriverManager.getConnection(connectionString,Configs.dbuser,Configs.dbpass);
} catch (SQLException e) {
e.printStackTrace();
}
return dbconnection;
}
}
这是 Configs ^ 的子类,到目前为止非常简单:
public class Configs {
protected String dbhost = "a host";
protected String dbport = "a port";
protected String dbuser = "a user";
protected String dbpass = "a password";
protected String dbname = "a name";
}
将在配置中添加更多内容,但在我弄清楚如何解决我遇到的错误之后(顺便说一句,导入了 mysql 库)