-2

I am using the following code in selenium, but I am not able to retrieve data from database. I am getting the errors "The result set has no current row"

My code is

public class Auto {

    public static void main(String[] args) throws InterruptedException, SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException
    {


        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        System.out.println("Driver loaded");


        Connection con=DriverManager.getConnection("jdbc:sqlserver://192.168.*****\\SQLEXPRESS/*****_DW/EPS:****;user=******;password=******; ");

        System.out.println("Driver loadedd");


    java.sql.Statement stmt= con.createStatement();
    ResultSet rs=stmt.executeQuery("select * from [*****_DW].[dbo].dim_grantee ");

    System.out.println("Query executed");

    while (rs.next());
    {
        String Name=rs.getString("NAME");

        System.out.println("Name is");
    }


}

closed as off-topic by dzieciou, NarendraC, Bharat Mane, c32hedge, Ray Oei Mar 11 at 21:17

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about software development unrelated to testing are off-topic here, but can be asked on Stack Overflow." – dzieciou, NarendraC, Bharat Mane, c32hedge
If this question can be reworded to fit the rules in the help center, please edit the question.

1

Change

while (rs.next());
{
    String Name=rs.getString("NAME");

    System.out.println("Name is");
}

to

while (rs.next())
{
    String Name=rs.getString("NAME");
    System.out.println("Name is");
}

i.e. remove semicolon from while line

0

The short version: Your query is not returning any rows.

The long version: You need to find out why your query is not returning any rows. The first step is to either step through the code with a debugger, or add a lot of print statements to determine what exactly is going on.

I suspect that either the table is empty or the connection is not properly formed. You might want to look at the answers to this Stack Overflow question for more information.

  • Why does rs.next() return true in that case? – Alexey R. Feb 11 at 14:13
  • We don't know from the description whether the error is being thrown on rs.next() or not. My assumption was that the error was being thrown by the rs.next() check. – Kate Paulk Feb 11 at 15:08
  • Kate, Connection is proper because for metdata it is working fine i can get the number of column count and all...that means connection is correct... – Shridhar Feb 12 at 5:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.