首页新闻找找看学习计划

mysql查询相关问题

0
悬赏园豆:50 [已解决问题] 解决于 2017-01-25 09:40

如图所示 查询不成 这个是用来查询账号密码用的 他那句话下边说的啥意思

问题补充:

package review.controller;

import review.dao.dataBaseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**

  • Created by 90860 on 2017/1/24.
    */
    @WebServlet(name = "LoginAction")
    public class LoginAction extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String account = request.getParameter("account");
    String password = request.getParameter("password");
    /**
    * 声明 连接 预处理声明 结果集 sql
    */
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String sql =null;
    try {
    sql = "select account,password from account where account=? and password=? ";
    System.out.println("执行的sql语句" + sql);
    conn = dataBaseUtil.getConnection();
    pstmt = conn.prepareStatement(sql);
    pstmt.setString(1, account);
    pstmt.setString(2, password);
    rs = pstmt.executeQuery();
    System.out.println(rs + "-----------" + rs.next());
    if (rs.next()) {
    // HttpSession session = request.getSession();
    System.out.println("登陆成功");
    request.getRequestDispatcher("/loginsuccess.jsp").forward(request, response);

// session.setAttribute("account",account);
request.setAttribute("account", account);
} else {
System.out.println("登录失败");
// request.getRequestDispatcher("/loginsuccess.jsp").forward(request, response);
response.sendRedirect(request.getContextPath() + "/index.jsp");
}
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
if (conn != null) {
conn.close();
}
if (rs!=null){
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
System.out.println("释放资源发生异常");
}
}

}


protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    doPost(request, response);
}

}


xnui7的主页 xnui7 | 初学一级 | 园豆:20
提问于:2017-01-24 22:14
< >
分享
最佳答案
1

查询语句加上 ‘?’ ‘’ 因为它是字符串


xnui7 | 初学一级 |园豆:20 | 2017-01-24 23:22
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册