索引:: 3处缺少IN或OUT参数

时间:2017-04-02 07:21:58

标签: java ojdbc

我是编程世界的新手。我试着做一个简单的登录,但是我收到了这个错误:

  

在index :: 3

处缺少IN或OUT参数

我试图找到答案,但我仍然无法识别编码中的问题。

这是我的LoginServlet

package apl;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import apl.LoginDao;


public class LoginServlet extends HttpServlet{

    private static final long serialVersionUID = 1L;

    public void doPost(HttpServletRequest request, HttpServletResponse response)  
            throws ServletException, IOException {  

        response.setContentType("text/html");  
        PrintWriter out = response.getWriter();  

        String i=request.getParameter("sid");  
        String n=request.getParameter("sname");
        String p=request.getParameter("sphone");  
        String u=request.getParameter("susername");  
        String w=request.getParameter("spassword");


        HttpSession session = request.getSession(true);
        if(session!=null)
        session.setAttribute("sid", i);

        if(LoginDao.validate(i,n,p,u,w)){  
            RequestDispatcher rd=request.getRequestDispatcher("welcome.jsp");  
            rd.forward(request,response);  
        }  
        else{  
            out.print("<p style=\"color:red\">Sorry username or password incorrect</p>");  
            RequestDispatcher rd=request.getRequestDispatcher("login.jsp");  
            rd.include(request,response);  
        }  

        out.close();  
    }  
} 

这是我的LoginDao

package apl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class LoginDao {

        public static boolean validate(String sid, String sname, String sphone, String susername, String spassword) {  

            boolean status = false;
            Connection conn = null;
            PreparedStatement pst = null;
            ResultSet rs = null;

            String driver = "oracle.jdbc.driver.OracleDriver";

            try {
                Class.forName(driver).newInstance();
                conn = DriverManager
                        .getConnection("jdbc:oracle:thin:@localhost:1521:xe","apl","system");

                pst = conn.prepareStatement("select * from SELLER where sid=?,sname=?,sphone=?,susername=? and spassword=?");

                pst.setString(1, sid);              
                pst.setString(2, sname);                
                pst.setString(3, sphone);
                pst.setString(4, susername);
                pst.setString(5, spassword);


                rs = pst.executeQuery();

                status = rs.next();            


            } catch (Exception e) {
                System.out.println(e);
            } finally {
                if (conn != null) {
                    try {
                        conn.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
                if (pst != null) {
                    try {
                        pst.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
                if (rs != null) {
                    try {
                        rs.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
            }
            return status;    
        }
    }

这是我的jsp文件

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Application</title>
</head>
<body>
    <form action="LoginServlet" method="post">
        <fieldset style="width: 300px">
            <legend> Login to App </legend>
            <table>
               <tr>
                    <td>Id</td>
                    <td><input type="text" name="sid" required="required" /></td>
                </tr>
                <tr>
                    <td>Password</td>
                    <td><input type="text" name="sname" required="required" /></td>
                </tr>
                <tr>
                    <td>Phone</td>
                    <td><input type="text" name="sphone" required="required" /></td>
                </tr>
                <tr>
                    <td>User name</td>
                    <td><input type="text" name="susername" required="required" /></td>
                </tr>
                <tr>
                    <td>Password</td>
                    <td><input type="password" name="spassword" required="required" /></td>
                </tr>
                <tr>
                    <td><input type="submit" value="Login" /></td>
                </tr>
            </table>
        </fieldset>
    </form>
</body>
</html>

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <servlet>
    <servlet-name>LoginServlet</servlet-name>
    <servlet-class>apl.LoginServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>LoginServlet</servlet-name>
    <url-pattern>/LoginServlet</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
  </welcome-file-list>

1 个答案:

答案 0 :(得分:1)

在您的SQL where子句中,and运算符丢失,因此您需要添加它,如下所示:

pst = conn.prepareStatement("select * from SELLER where sid=?
 and sname=? and sphone=? and susername=? and spassword=?")