java while (resultset.next()) 不会 return 同一列中的所有数据
java while (resultset.next()) does not return all data in the same column
我需要你的帮助。我希望结果集获取 member_code 列中的所有数据,但它只获取 1 个数据。如何使用循环获取 member_code 中的所有数据?这是我的代码:
public String membercode() throws SQLException{
String member="";
String sql = "SELECT member_code FROM member";
java.sql.Connection conn = (Connection) koneksi.config();
java.sql.Statement stm = conn.createStatement();
java.sql.ResultSet res = stm.executeQuery(sql);
while(res.next()) {
member = res.getString("member_code");
}
return member;
}
您需要 assemble 和 return 一个“列表”。例如:
public List<String> membercode() throws SQLException{
List<String> members = new ArrayList<String>();
String sql = "SELECT member_code FROM member";
java.sql.Connection conn = (Connection) koneksi.config();
java.sql.Statement stm = conn.createStatement();
java.sql.ResultSet res = stm.executeQuery(sql);
while(res.next()) {
member = res.getString("member_code");
members.add(member);
}
return members;
}
我需要你的帮助。我希望结果集获取 member_code 列中的所有数据,但它只获取 1 个数据。如何使用循环获取 member_code 中的所有数据?这是我的代码:
public String membercode() throws SQLException{
String member="";
String sql = "SELECT member_code FROM member";
java.sql.Connection conn = (Connection) koneksi.config();
java.sql.Statement stm = conn.createStatement();
java.sql.ResultSet res = stm.executeQuery(sql);
while(res.next()) {
member = res.getString("member_code");
}
return member;
}
您需要 assemble 和 return 一个“列表”。例如:
public List<String> membercode() throws SQLException{
List<String> members = new ArrayList<String>();
String sql = "SELECT member_code FROM member";
java.sql.Connection conn = (Connection) koneksi.config();
java.sql.Statement stm = conn.createStatement();
java.sql.ResultSet res = stm.executeQuery(sql);
while(res.next()) {
member = res.getString("member_code");
members.add(member);
}
return members;
}