SQL help please.

Discussion in 'Plugin Development' started by ImDeJay, Apr 7, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    ImDeJay

    I'm trying to populate a hashmap with items from a result set.

    my problems:

    ResultSet was skipping my first entry, so there are actually 4 items in the table, but its only grabbing 3 while getting the info this way:

    Code:java
    1. while(rs.next()){
    2.  
    3. String playerName = rs.getString("playerName");
    4. int kills = rs.getInt("kills");
    5.  
    6. myMap.put(playerName, kills);
    7.  
    8. }


    so i changed my code to:

    Code:java
    1.  
    2. do{
    3. String playerName = rs.getString("playerName");
    4. int kills = rs.getInt("kills");
    5.  
    6. myMap.put(playerName, kills);
    7.  
    8. } while(rs.next));


    ^^the above code is adding all the entries, but im getting SQLException

    Code:
    java.sql.SQLException: Before start of result set
    what is the best way to get ALL my entries from a table using MySQL and adding the items to a hashmap without skipping the first entry?
     
  2. Offline

    duker02

    I don't know if this makes a difference, but change to this:
    Code:java
    1. if(rs.next()){
    2.  
    3. String playerName = rs.getString("playerName");
    4. int kills = rs.getInt("kills");
    5.  
    6. myMap.put(playerName, kills);
    7.  
    8. }
     
Thread Status:
Not open for further replies.

Share This Page