能帮我看看那错了吗?每到pst。excuteQuery的时候就sql异常,
package util;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import empty.User;
public class QueryUser {
private static Connection con;
private static PreparedStatement pst;
private static ResultSet rst;
User o=new User();
public ArrayList<User> queryUser(String username) throws ClassNotFoundException, SQLException{
con=jdbcUtil.getConnection();
String sql="setect username,password from hotel where username=?";
pst=con.prepareStatement(sql);
pst.setString(1,username);
rst=pst.executeQuery();//出错
ArrayList<User> user=new ArrayList<User>();
while(rst.next()){
String name=rst.getString(1);
String password=rst.getString(2);
System.out.println("用户名--"+username);
System.out.println("密码---"+password);
o.getUsername();
o.getUserpassword();
}
user.add(o);
rst.close();
pst.close();
con.close();
return user;
}
}
/////////////////////////
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import util.QueryUser;
import empty.User;
public class LoginServlet extends HttpServlet {
//private String username;
private String password;
private String phone;
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String username=request.getParameter("username");
password=request.getParameter("userpwd");
User o=new User();
o.setUsername(username);
o.setUserpassword(password);
QueryUser que =new QueryUser();
try {
ArrayList<User> name=que.queryUser(username);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
RequestDispatcher requestDispatcher1 = request.getRequestDispatcher("order.html");
requestDispatcher1.forward(request, response);
}
}