我正在尝试通过 jsp 访问我的数据库,并且我有以下代码:
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
String value = "vuoto";
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/onlinebookstore", "root", "sesame");
Statement statement = connection.createStatement();
ResultSet result = statement.executeQuery("SELECT * FROM users WHERE email = '" + username + "' " + "AND" + " password = '" + password + "'");
if(result.next()) {
value = "eccomi";
}
connection.close();
%>
我不明白为什么我需要使用 Class.forName 因为我从 JDBC 4.0 中读到它是没有必要的,但是如果我删除该语句它就不起作用。在我的库中,我添加了 MySQL JDBC Driver -mysql-connector-java-5.1.23-bin.jar