以下代码从我的数据库中获取我需要的信息,但不会打印出所有信息。首先我知道它是从表中获取所有正确的信息,因为我已经在SQL开发人员中尝试了查询。结果集返回3行,但我只能打印2?
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
conn = getConnection();
String query = "SELECT menu.menu_id, menu_title, dish.dish_id, dish_name, dish_description, dish_price, menu.week_no "
+ "FROM menu, dish, menu_allocation "
+ "WHERE menu.active = '1' "
+ "AND menu.menu_id = menu_allocation.menu_id "
+ "AND dish.dish_id = menu_allocation.dish_id "
+ "AND menu.week_no IN (09, 10, 11)";
stmt = conn.createStatement();
rs = stmt.executeQuery(query);
MenuList list = null;
while (rs.next()) {
list = new MenuList(rs);
System.out.println(rs.getRow());
}
for (int pos = 0; pos < list.size(); pos++) {
Menu menu = list.getMenuAt(pos);
System.out.println(menu.getDescription());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
rs.close();
stmt.close();
conn.close();
} catch (SQLException e) {
}
}
}
来自终端的输出如下所示:
3 //Number of rows
Fish and Chips //3rd row
Chocolate Cake //2nd row
//Here should be 1st row
BUILD SUCCESSFUL (total time: 2 seconds)
即使它说有三排它只有印刷两个。任何人都可以看到上述问题吗?
如果你有更多的信息加入到做正确的事是编辑您的问题或添加评论。不要发布一些答案,这不是一个答案,因为看着你的问题的人可能看不到它。 – 2012-03-01 13:49:14