Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8295177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:29:26+00:00 2026-06-08T14:29:26+00:00

My Login Form is not working ,Can any please help me… public class LoginServlet

  • 0

My Login Form is not working ,Can any please help me…

public class LoginServlet extends HttpServlet {

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    String userName=request.getParameter("userName");
    String password=request.getParameter("password");
     DataPersistor d=new DataPersistor();
    try {
        if( d.isValidateUser(userName, password)){
               HttpSession session=request.getSession();
         session.setAttribute("name", userName);
         response.sendRedirect("index.jsp");
        }



         else{
             response.sendRedirect("login.jsp");

         }
    } catch (SQLException ex) {
        Logger.getLogger(LoginServlet.class.getName()).log(Level.SEVERE, null, ex);
    }


    } 




}

This is My Data Persistor Class.I am getting the Value From the Database ,

public class DataPersistor {
    Connection con;

public DataPersistor() {
    con = DBConnector.getConnection();
}

public void registerUser(User user) {
    try {
        Statement stmt = con.createStatement();
        String query = "INSERT INTO user VALUES ('" + user.getUserName() + "','" + user.getPassword() + "','" + user.getEmail() + "','" + user.getLastName() + "','" + user.getFirstName() + "','false')";
        stmt.execute(query);



    } catch (SQLException ex) {
        Logger.getLogger(DataPersistor.class.getName()).log(Level.SEVERE, null, ex);
    }





}
public boolean isValidateUser(String username,String password) throws SQLException{
    boolean result=false;
    PreparedStatement ps;
     Statement stmt = con.createStatement();
        String query = "SELECT * FROM  user WHERE username='" + username + "' and password='"+password+"'";
        ps=con.prepareStatement(query);
        ps.setString(1,username);
        ps.setString(2, password);

        ResultSet rs=ps.executeQuery();

        if(rs.next()==true){

            result=true;
        }
        return result;





}

}


after Clean and Build

Jul 29, 2012 8:51:46 PM com.asiahospital.servlet.LoginServlet doPost
SEVERE: null
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
    at com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3729)
    at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3713)
    at com.mysql.jdbc.PreparedStatement.setString(PreparedStatement.java:4553)
    at com.asiahospital.db.DataPersistor.isValidateUser(DataPersistor.java:50)
    at com.asiahospital.servlet.LoginServlet.doPost(LoginServlet.java:32)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)`enter code here`
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:29:31+00:00Added an answer on June 8, 2026 at 2:29 pm

    It looks like your connection has not been initialised properly.

    Statement stmt = con.createStatement();
    

    Check what is returned from

    DBConnector.getConnection()
    

    From your updated post(!), the problem is that your prepared statement doesnt contain any ‘?’ placeholder characters.

    public boolean isValidateUser(String username, String password) throws SQLException {
        boolean result = false;
    
        String query = "SELECT * FROM  user WHERE username='?' and password='?'";
        PreparedStatement ps = con.prepareStatement(query);
        ps.setString(1, username);
        ps.setString(2, password);
    
        ResultSet rs = ps.executeQuery();
    
        if (rs.next() == true) {
           result = true;
        }
    
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to ensure that the user login form for Drupal can not be
I am working on login/signup module(FYI no rolls/membership just a simple login form),data flow
Login Form: $authAdapter = Zend_Registry::get('authAdapter'); $authAdapter ->setIdentity($formData['email']) ->setCredential($password) ->setCredential(1); Bootstrap: protected function _initAuth(){ $this->bootstrap('db');
My login form is located at /account/login . GET requests to this URL cause
I'm building a login form composite component. The page that uses it will pass
How to build a login form on the startingpage within a little widget on
I have a simple login form and have jQuery validate replacing the field labels
I have a login form consisting of a Form with two TextInput's. I want
I have a login form which appears at the top of all of my
I have a usual login form consisting of two input fields, one for login,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.