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 8425697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:20:38+00:00 2026-06-10T04:20:38+00:00

public UserBean authenticate(String username,String password){ PostGresDAO pg=new PostGresDAO(); //creates new connection Connection conn=pg.getConnecion(); //return

  • 0
public UserBean authenticate(String username,String password){
    PostGresDAO pg=new PostGresDAO();   //creates new connection
    Connection conn=pg.getConnecion();  //return connection object
    PreparedStatement ps;
    ResultSet rs;
    String query="select password,name from scg_users where username=?";
    UserBean ub=null;
    boolean authenticated=false;
    try{
        ps=conn.prepareStatement(query);
        ps.setString(1, username);
        rs=ps.executeQuery();

        if(rs!=null){

            authenticated=password.equals(rs.getString(1));  //exception raised here
            if(authenticated){
                ub=new UserBean();
                ub.setUser(rs.getString(2));
                ub.setUsername(username);
            }
        }
    }
    catch(SQLException e){
        e.printStackTrace();
    }
    return ub;
}

I am using this code for authenticating a user. The username and password are extracted from the request parameter and passed onto this method for authentication. But it throws a:

org.postgresql.util.PSQLException: ResultSet not positioned properly, perhaps you need to call next.

Please advice.

  • 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-10T04:20:39+00:00Added an answer on June 10, 2026 at 4:20 am

    The error is telling you exactly what’s wrong – you’re not calling next() on your ResultSet to get to the first row of the results.

    This line:

    if(rs!=null)
    

    is pointless as far as I know; I don’t believe executeQuery will ever return null. If there’s a problem in your query, an exception will be thrown. If there are no results, it will return an empty result set. To see if there’s a row, you should call next() and check the return value:

    if (rs.next())
    

    Additionally:

    • Catching an exception and just printing the stack trace without rethrowing is almost always the wrong approach
    • Your code suggests that you’re storing passwords in plain text. Please don’t. Really, really don’t.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class Test { public static void main(String[] args) { DemoAbstractClass abstractClass = new
public String getBrotherHood() throws Exception{ client = new DefaultHttpClient(); get = new HttpGet(uri); res
public static class TestTask extends AsyncTask<Void, Integer, Integer> { private String stacktrace; public TestTask
public static void main(String[] args) { int i = 0; while(i==0){ System.out.println(Possibilities: R, T,
public class MyClass { public string MyProperty{ get; set; } Now, I would like
public void openOptions() { Intent intent=new Intent(this,Game.class); //intent.putExtra(razmer, level); startActivity(intent); // Intent intent=new Intent(this,Options.class);
Let's say I have a query getUser with two parameters - userName and password.
I am trying to run this basic JPA/EJB code: public static void main(String[] args){
I have the following JSF 2.1 page <h:selectOneRadio value=#{userBean.newUser}> <f:selectItem itemValue=0 itemLabel=new User />
lets say I have a class like this: public class MyClass { private String

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.