首页 > 解决方案 > While(ResultSet.Next() 在第一列条目后跳过,不返回任何数据

问题描述

尝试使用 derby JavaDB 数据库中的条目填充 HashMap,而(rs.next() 在第一列条目后跳过

我尝试将列号更改为列名,更改 ResultSet 查询,连接字符串。

HashMap<String, Student> students = new HashMap();
    try
    {
       Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/AceDrivingSchool", "ADC", "ADC");
       Statement stmt = conn.createStatement();
       ResultSet rs = stmt.executeQuery("SELECT * FROM ADC.STUDENT");

       while(rs.next())
       {
           String studentId = rs.getString(1);
           String emailAddress = rs.getString(2);
           String forename = rs.getString(3);
           String surname = rs.getString(4);
           String addressLine1 = rs.getString(5);
           String addressLine2 = rs.getString(6);
           String postcode = rs.getString(7);
           String telephoneNo = rs.getString(8);
           String getGender = rs.getString(9); 
           char gender = getGender.charAt(0);
           String password = rs.getString(11);
           boolean isRegistered = rs.getBoolean(12);
           boolean isVerified = rs.getBoolean(13);
           boolean passedTheory = rs.getBoolean(14);
           boolean passedPractical = rs.getBoolean(15);
           String drivingLicenseNo = rs.getString(16);

           new student  //summary 

           students.put(emailAddress, student);



       }
       conn.close();
    }
    catch(Exception ex)
    {
        String message = ex.getMessage();
    }
    return students;
}

变量应该显示从数据库中读取的相应数据

标签: javasqlhashmapderby

解决方案


推荐阅读