2016-11-02 4 views
0

本当に助けが必要です。 ResultSetMetaDataとResultSetを使用してデータベースからデータを取得しようとしています。また、私はストアドプロシージャを使用しています。プログラムは実行されますが、実行して3行の結果を期待している場合は、代わりに2を返します。たとえば、ユーザーに位置を入力するように要求し、その位置に6人のプレーヤーがいる場合、 6人のプレーヤーの代わりに5人のプレイヤーを教えてください。ここでJavaとSQL:ResultSetMetaDataとResultSet

はあなたが

if (!rs.next()) { 

自体に最初のインデックスを読んでいる私のコード

  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

答えて

3

です。これにより、カーソルが次の行に移動します。これを削除する必要があり、すべての行が表示されます。

+0

です。ありがとうございます – William

+0

それは素晴らしいです!あなたが望むなら、あなたはその答えを受け入れるかもしれません。 –

関連する問題