为什么在运行时出现此异常? 我在libraries文件夹中添加了ojdbc.jar 之后抛出异常。
是ojdbc.jar引起的问题吗?
这是我的代码:
public class DBManager {
private Connection connection=null;
private PreparedStatement preparedStatement=null;
private ResultSet resultSet = null;
private String URL;
private String userName;
private String pass;
public DBManager(String URL,String userName,String pass){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
}catch(ClassNotFoundException e){
e.printStackTrace();
}
try{
connection = DriverManager.getConnection(URL, userName, pass);
}catch(SQLException e){
e.printStackTrace();
}
}
public ResultSet validate(Users user,String sql){
try{
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1,user.getEmail());
preparedStatement.setString(2,user.getPassword());
resultSet = preparedStatement.executeQuery();
}catch(SQLException e){
e.printStackTrace();
}
return resultSet;
}
}
public class MyServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Users user = new Users();
user.setEmail(request.getParameter("email"));
user.setPassword(request.getParameter("password"));
try {
DBManager manager = new DBManager("jdbc:oracle:thin:@localhost:1521:XE", "databaseName", "Password");
String sql = "SELECT FIRSTNAME,LASTNAME FROM USERS WHERE EMAIL=? and PASSWORD=?";
ResultSet resultSet = manager.validate(user, sql);
while (resultSet.next()) {
user.setFname(resultSet.getString("FIRSTNAME"));
user.setLname(resultSet.getString("LASTNAME"));
}
request.setAttribute("user", user);
response.sendRedirect("welcome.jsp");
} catch (Exception e) {
e.printStackTrace();
}
}
和index.html:
<html>
<head>
<title>Login</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div id = "main">
<form action="MyServlet" method="POST">
<table>
<tr>
<th>
Your Email:
</th>
<td>
<input type = "email" name="emial">
</td>
</tr>
<tr>
<th>
Your Password:
</th>
<td>
<input type = "password" name="password">
</td>
</tr>
<tr>
<th>
</th>
<td>
<input type = "submit">
</td>
</tr>
</table>
</form>
</div>
</body>
欢迎jsp页面是
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome</title>
</head>
<body>
<h1> Welcome
<%
Users user = (Users)request.getAttribute("user");
out.print(user.getFname()+" "+user.getLname());
%>
</h1>
</body>