PreparedStatement pstmt=conn.prepareStatement(sql);错误
publicclassacceptUserLoginextendsHttpServlet{publicvoiddoPost(HttpServletRequestreque...
public class acceptUserLogin extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session=request.getSession(true);
Connection conn=null;
String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=bookstore";
String name="guest";
String psword="123";
try{
Class.forName(driver); //加载数据库驱动程序
//创建数据库连接对象
conn = DriverManager.getConnection(
url,name,psword);
}catch(ClassNotFoundException e1){
}catch(SQLException e2){}
String yhlx=request.getParameter("yhlx");
String username=request.getParameter("username");
String password=request.getParameter("password");
try{
String sql="select * FROM GUEST WHERE USERNAME=? AND PSW=?";
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1,username);
pstmt.setString(2,password);
ResultSet rst = pstmt.executeQuery();
if(rst.next()){
if(yhlx.equals("ptyh")){
session.setAttribute("username", username);
response.sendRedirect("index1.jsp");
}
if(yhlx.equals("gly")){
session.setAttribute("username", username);
response.sendRedirect("index2.jsp");
}
} 展开
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session=request.getSession(true);
Connection conn=null;
String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=bookstore";
String name="guest";
String psword="123";
try{
Class.forName(driver); //加载数据库驱动程序
//创建数据库连接对象
conn = DriverManager.getConnection(
url,name,psword);
}catch(ClassNotFoundException e1){
}catch(SQLException e2){}
String yhlx=request.getParameter("yhlx");
String username=request.getParameter("username");
String password=request.getParameter("password");
try{
String sql="select * FROM GUEST WHERE USERNAME=? AND PSW=?";
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1,username);
pstmt.setString(2,password);
ResultSet rst = pstmt.executeQuery();
if(rst.next()){
if(yhlx.equals("ptyh")){
session.setAttribute("username", username);
response.sendRedirect("index1.jsp");
}
if(yhlx.equals("gly")){
session.setAttribute("username", username);
response.sendRedirect("index2.jsp");
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询