尝试使用来自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;
}
变量应显示从数据库读取的相应数据