我想连接到我的MySQL服务器,但驱动程序不起作用。 我该如何解决这个问题,或者我做错了什么?我是否需要导入额外的库(我没有这样做)?
这是我的代码:
public void Connection() {
String retrievedUserName = "";
String retrievedPassword = "";
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://domainexample.com", "username", "passwoord");
PreparedStatement statement = con.prepareStatement("SELECT * FROM Gebruiker WHERE users= '" + "username" + "'");
ResultSet result = statement.executeQuery();
while (result.next()) {
retrievedUserName = result.getString("gebruikersnaam");
retrievedPassword = result.getString("password");
}
System.out.println(retrievedUserName + " passwoord = " + retrievedPassword);
} catch (Exception e) {
e.printStackTrace();
}
}