我真的需要帮助。我正在尝试使用ResultSetMetaData和ResultSet从我的数据库中检索数据。我也在使用存储过程。该程序运行find,但是当我运行它并期待该行的3个结果时,它会给我2. 例如,如果我要求用户输入一个位置并且该位置有6个玩家,它会给我5个玩家而不是6个玩家。
这是我的代码
if (!rs.next()) {
System.out.println("There is no match in the database " + position);
}
else {
System.out.println(String.format(" " + " %-19s %s", "Name",
"Rank") + "\t" + String.format("%-11s %s", "Position",
"School") + "\t" + String.format("%-6s %s",
"Age", "War") + "\n-----------------"
+ "-------------------------------------------------");
while (rs.next()) {
int rank = 0, age = 0;
String name = null, pos = null, sch = null;
double war = 0;
for (int i = 1; i < colum - 1; i++) {
rank = rs.getInt(1);
name = rs.getString(2);
pos = rs.getString(3);
sch = rs.getString(4);
age = rs.getInt(5);
war = rs.getDouble(6);
}
When I run my java code I get this result. It's not getting the first index in the list
When I call my stored procedure in MYSQL Workbench, I get this result
答案 0 :(得分:3)
您已阅读
中的第一个索引 if (!rs.next()) {
本身。这会将光标移动到下一行。您将不得不删除它,它将提供所有行。