我正在尝试在我的数据库中插入数据,但是我收到了这个错误:
$scope.promo1 = "(A|B)";
$scope.promo2 = "(C|D)";
$scope.promo3 = "((A|B) | (C|D))";
这是我在数据库中插入数据的jsp文件。
insert.jsp
javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
我已经:
<%@page import = "java.io.*, java.sql.*, java.util.*"%>
<%@page import = "javax.servlet.http.*, javax.servlet.*"%>
<%
String name = request.getParameter("name");
String email = request.getParameter("email");
String uname = request.getParameter("uname");
String pass = request.getParameter("pass");
String connectionURL = "jdbc:mysql://localhost:3306/dbmembers";
Connection connection = null;
PrepareStatament pstatement = null;
Class.forName("com.mysql.jdbc.Driver");
int updateQuery = 0;
if (name!=null && email!=null && uname!=null && pass!=null) {
if (name!="" && email!="uname" && pass!="") {
try{
connection = DriverManager.getConnection(connectionURL, "root","");
String queryString = "INSERT INFO tablemem (Name, Email, Uname, Pass) VALUES (?,?,?,?)";
pstatememt = connection.preparedStatement (queryString);
pstatement.setString(1, name);
pstatement.setString(2, email);
pstatement.setString(3, uname);
pstatement.setString(4, pass);
updateQuery = pstatement.executeUpdate();
if (updateQuery != 0) { %>
<table>
<tr>
<th>Successfully Registered</th>
<th><a href="login.jsp">Login here</a></th>
</tr>
</table>
<%
}
} catch (Exception ex) {
out.println("Unable to connect to Database");
}
finally {
pstatement.close();
connection.close();
}
}
}
%>
放入WEB-INF / lib 但我仍然遇到同样的错误。我错过了什么吗?
答案 0 :(得分:0)
确保已将连接器jar文件添加到构建路径中 要这样做,请右键单击jar文件,然后单击“添加以构建路径”