为了账号安全,请及时绑定邮箱和手机立即绑定

能帮我看看那错了吗?每到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);

}


}


正在回答

1 回答

请查看你的sql语句

“String sql="setect username,password from hotel where username=?";”

原句中的select的关键字错了

0 回复 有任何疑惑可以回复我~
#1

慕UI8820655 提问者

非常感谢!
2016-10-28 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

能帮我看看那错了吗?每到pst。excuteQuery的时候就sql异常,

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信