select * from login where userid='loginName' and password='loginPasswd'

解决方案 »

  1.   

    "select * from login where userid='"+loginName+"' and password='"+loginPasswd+"'"
      

  2.   

    怎么还提示有这种错误:You have an error in your SQL syntax near 'where userid='null' and password='null' ???????????
      

  3.   

    "select * from login where userid='"+loginName+"' and password='"+loginPasswd+"';"
      

  4.   

    有可能前一个form中根本没有得到的输入值
    你在sql语句之前out.print一下,看看有没有得到值!
      

  5.   

    我在form中输入11,11后提交,有有如下错误:You have an error in your SQL syntax near 'where userID='11' and password='11' !
    唉,受不了了!
      

  6.   

    //定义登录时用到的变量并对变量进行初始化
    String logNameA,passwdA,logNameB,passwdB;
    boolean loginOKA=false,loginOKB=false; if(request.getParameterValues("submit1")!=null){

    logNameA=request.getParameter("nameA");
    logNameB=request.getParameter("nameB");
    passwdA=request.getParameter("passwdA");
    passwdB=request.getParameter("passwdB");

    //logNameA=getStr(logNameA);
    //logNameB=getStr(logNameB);
    //passwdA=getStr(passwdA);
    //passwdB=getStr(passwdB);
    int rowCountA=0,rowCountB=0;

    String mysqlDriver="org.gjt.mm.mysql.Driver";
    String connStr="jdbc:mysql://localhost/ca";
    Connection conn=null;
    ResultSet RS=null;

    Class.forName(mysqlDriver);
    conn=DriverManager.getConnection(connStr,"root","");
    Statement stmt=conn.createStatement();
    String sql="select * from login where where userID='"+logNameA+"' and password='"+passwdA+"' ";
    RS=stmt.executeQuery(sql); try{

    while(RS.next()){
    rowCountA++;
    }

    if(rowCountA!=0) loginOKA=true;

    }
    catch(Exception e)
    {
    e.printStackTrace();
    } sql="select * from login where userID='"+logNameB+"'and password='"+passwdB+"' ";
    RS=stmt.executeQuery(sql);
    try
    {

    while(RS.next()){
    rowCountB++;
    }

    if(rowCountB!=0) loginOKB=true;

    }
    catch(Exception e)
    {
    e.printStackTrace();
    } if ( loginOKA&&loginOKB ) {
    session.setAttribute("adminA",logNameA);
    session.setAttribute("adminB",logNameB);
    response.sendRedirect("http://localhost:8080/admins/index.html"); }
    else{ //提示用户登录错误信息 //管理员名或者密码不正确!
    response.sendRedirect("http://localhost:8080/admins/error.html"); }
    }%><html>
    <head><title>管理员登录</title></head>
    <body>
    <br>
    <br>
    <h1><b><center>管理员登录</center><b></h1>
    <br>

    <form  action="login.jsp" method="post" id="loginForm"><table align="center"cellspacing="30">
    <tr>
    <th><h3><b>管理员A</h3></b></th> <th></th>
    <th><h3><b>管理员B</h3></b></th>
    </tr>
    <tr>
    <td><center>姓名A:<input type="text"name="nameA"size="20"></center></td> <th></th>
    <td><center>姓名B:<input type="text"name="nameB"size="20"></center></td>
    </tr> <tr>
            <td><center>密码A:<input type="password"name="passwdA"size="20"></center></td> <th></th>
            <td><center>密码B:<input type="password"name="passwdB"size="20"></center></td>
            </tr>        <tr></tr>        <tr>
            <td align="right"><input type="submit" name="submit1"value="确定"size="20"</td> <th></th>
            <td align="left"><input type="reset" name="reset1"value="取消"size="20"></td>
            </tr> </table></form></body></html>
      

  7.   

    会不会是数据库连接的地方有问题?
    我用的是SQL Server,不太明白你的代码。
      

  8.   

    你在数据库的login表中定义的userID和password是什么类型的?如果userID是number,那么sql应是:
      sql="select * from login where userID="+logNameB+" and password='"+passwdB+"'";
      

  9.   

    在程序中定义的是string就应该没问题吧!
    或者换成int试试??
      

  10.   

    会不会是编码问题   logNameA=request.getParameter("nameA");
       logNameA= new String( logNameA.getBytes("ISO8859_1"),"gb2312");
      试试看!!