注释代码:public List<score> list(int start, int count) { List<score> scores = new ArrayList<score>(); String sql = "SELECT * FROM 店铺库存信息 order by number offset ? rows fetch next ? rows only "; try (Connection c = getConnection(); PreparedStatement ps = c.prepareStatement(sql);) { ps.setInt(1, start); ps.setInt(2, count); ResultSet rs = ps.executeQuery(); while (rs.next()) { score score1 = new score(); String name = rs.getString("name"); String myclass = rs.getString("myclass"); int number= rs.getInt("number"); int Chinesegrade = rs.getInt("Chinesegrade"); int Mathgrade = rs.getInt("Mathgrade"); int Englishgrade= rs.getInt("Englishgrade"); score1.name = name; score1.myclass = myclass; score1.Chinesegrade = Chinesegrade; score1.Mathgrade = Mathgrade; score1.Englishgrade = Englishgrade; score1.number = number; scores.add(score1); } } catch (SQLException e) { e.printStackTrace(); } return scores; }
时间: 2024-02-14 18:24:21 浏览: 74
// 以下是注释代码:
/**
* 获取店铺库存信息列表
* @param start 起始位置
* @param count 获取数量
* @return 店铺库存信息列表
*/
public List<score> list(int start, int count) {
// 定义一个空的店铺库存信息列表
List<score> scores = new ArrayList<score>();
// 定义 SQL 语句,按照 number 字段排序,获取指定数量的店铺库存信息
String sql = "SELECT * FROM 店铺库存信息 order by number offset ? rows fetch next ? rows only ";
try (Connection c = getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {
// 设置 SQL 语句中的参数
ps.setInt(1, start);
ps.setInt(2, count);
// 执行 SQL 语句,获取结果集
ResultSet rs = ps.executeQuery();
// 遍历结果集,将每条记录转换成一个 score 对象,并添加到店铺库存信息列表中
while (rs.next()) {
score score1 = new score();
String name = rs.getString("name");
String myclass = rs.getString("myclass");
int number= rs.getInt("number");
int Chinesegrade = rs.getInt("Chinesegrade");
int Mathgrade = rs.getInt("Mathgrade");
int Englishgrade= rs.getInt("Englishgrade");
score1.name = name;
score1.myclass = myclass;
score1.Chinesegrade = Chinesegrade;
score1.Mathgrade = Mathgrade;
score1.Englishgrade = Englishgrade;
score1.number = number;
scores.add(score1);
}
} catch (SQLException e) {
e.printStackTrace();
}
// 返回店铺库存信息列表
return scores;
}
阅读全文