Get Number of Rows returned by ResultSet in Java

前端 未结 14 1273
挽巷
挽巷 2020-11-29 20:35

I have used a ResultSet that returns certain number of rows. My code is something like this:

ResultSet res = getData();
if(!res.next())
{
    Sy         


        
14条回答
  •  没有蜡笔的小新
    2020-11-29 20:54

    res.next() method will take the pointer to the next row. and in your code you are using it twice, first for the if condition (cursor moves to first row) then for while condition (cursor moves to second row).

    So when you access your results, it starts from second row. So shows one row less in results.

    you can try this :

    if(!res.next()){ 
        System.out.println("No Data Found");  
    }
    else{
        do{
           //your code
        } 
        while(res.next());
    }
    

提交回复
热议问题