Illegal operation on empty result set

感情迁移 提交于 2019-11-28 02:17:47

You haven't checked Whether your result set is empty or not before actually retriving values from Result set...

next() returns true if there is a data in the result set, false it there is not data at the a cursor position Place your code like this

While(rs.next())
{
    pName = rs.getString("productName");
    System.out.println("Product: " + pName);

    // MATA IN ANTAL
    System.out.println("\nEnter amount:");
    GroceryStore.amount = GroceryStore.scan.nextInt();


    pPrice = rs.getDouble("productPrice");
}

You are not checking whether your result set has any data or row in it.

ResultSet rs = stmt.executeQuery();
rs.next();
...
...

You should check whether your result is empty or having any row:

ResultSet rs = stmt.executeQuery();
if(rs.next()){
.....
your code
.....
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!