user3195025
user3195025

Reputation: 1

Exhausted Result Set

I am developing a project for Online Banking System. I want to retrieve a data from database using JDBC. However, it is showing Exhausted result exception though the query is returning a row in SQLPlus. Please Help. Here's the Code:

try
{

    Class.forName("oracle.jdbc.OracleDriver");

    con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "hr", "XXXXXX");
    String pass = 'sid';
    String user = 'sid';
    String accountnumber = '2345';
    String sql = "select * from user_info where account_number=?";


    s1 = con.prepareStatement(sql);
    s1.setString(1,accountnumber);

    rs1 = s1.executeQuery(sql);
    rs1.next();

    if(user.equals(rs1.getString("user_name"))) 
    {
        if(pass.equals(rs1.getString("password")))
        {
            if(accountnumber.equals(rs1.getString("account_number")))
            {
                new AccountInformation(accountnumber).setVisible(true);
            }
            else
            {
                JOptionPane.showMessageDialog(this, "Account Number is Incorrect");
            }
        }
        else
        {
            JOptionPane.showMessageDialog(this, "Password is Incorrect");
        }
    }
    else
    {
        JOptionPane.showMessageDialog(this, "User Name is Incorrect");
    }
}
catch(Exception e)
{
    JOptionPane.showMessageDialog(this,e);
}

Upvotes: 0

Views: 64

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201447

You threw away your bind parameter when you passed the SQL to Statement#executeQuery - use this one from PreparedStatement...

rs1=s1.executeQuery();
// rs1=s1.executeQuery(sql);

// check if you got a row
if (rs1.next()) {
  // as before....
}

Upvotes: 2

Related Questions