[英]Java and SQL: ResultSetMetaData and ResultSet
I really need help. 我真的需要帮助 I am trying to retrieve a data from in my database using ResultSetMetaData and ResultSet.
我正在尝试使用ResultSetMetaData和ResultSet从数据库中检索数据。 Also I am using a stored Procedure.
另外,我正在使用存储过程。 The program is run find, however when I run it and be expecting 3 result from the row, instead it will give me 2. For example if I ask a user to enter a position and there are 6 player in that position, it will give me 5 players instead of 6 player.
该程序运行查找,但是当我运行它并期望从该行获得3个结果时,它将给出2。 例如,如果我要求用户输入一个位置并且该位置有6个玩家,它将给出我5个玩家,而不是6个玩家。
Here is my code 这是我的代码
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. 当我运行Java代码时,我得到了这个结果。 It's not getting the first index in the list
它没有获得列表中的第一个索引
When I call my stored procedure in MYSQL Workbench, I get this result 当我在MYSQL Workbench中调用存储过程时,得到了这个结果
You have read first index in 您已阅读第一个索引
if (!rs.next()) {
itself. 本身。 This will move the cursor to the next row.
这会将光标移动到下一行。 You will have to remove this and it will give all the rows.
您将必须删除它,它将给出所有行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.