我收到此SQLServerException:“结果集没有当前行”。不了解

时间:2018-09-18 02:21:22

标签: java

我正在尝试连接到DB并从DB执行结果。 我收到以下错误。

Error: com.microsoft.sqlserver.jdbc.SQLServerException: The result set has no current row

public void getData() {
    try {           
        String query = "Select RetroRequestID, FirstName, LastName from RetroRequest_HMEarnOnOA where AccountNumber = 101930804";
        rs = st.executeQuery(query);
        System.out.println("Records from Database");
        while(rs.next());
        {
            String RetroRequestID = rs.getString("RetroRequestID");
            String FirstName = rs.getString("FirstName");
            String LastName = rs.getString("LastName");

            System.out.println("RetroRequestID: "+RetroRequestID+"   "+"FirstName: "+FirstName+"    "+"LastName: "+LastName);
        }   
    } catch(Exception ex) {
        System.out.println("Error: "+ex);
    }

1 个答案:

答案 0 :(得分:0)

if语句后有一个分号,而while则充当空语句:

 while(rs.next()); {  // remove the semi-colon

这将导致ResultSet的游标遍历所有行,直到没有行指向为止,从而导致异常。