Solved Get more then one result out of mysql

Discussion in 'Plugin Development' started by 0LUMIN4T0R, Nov 11, 2016.

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

    0LUMIN4T0R

    Hey Guys,
    i'm coding a little minigame at the moment and i want to save the locations, where an items spawn, in an database in mysql. But I get a NullPointerException in line 19.
    Code:
    public static ArrayList getBronze(){
            Integer x = 0;
            Integer y = 0;
            Integer z = 0;
            ArrayList<Location> locs = new ArrayList<Location>();
                try {
    //next line is line 19
                    ResultSet rs = Main.mysql.query("SELECT * FROM Locations WHERE TYPE = '1'");
                    while(rs.next()){
                    if(!(rs.next()) || (Integer.valueOf(rs.getInt("XWERT")) == null));
                    x = rs.getInt("XWERT");   
                    if(!(rs.next()) || (Integer.valueOf(rs.getInt("YWERT")) == null));
                    y = rs.getInt("YWERT");
                    if(!(rs.next()) || (Integer.valueOf(rs.getInt("ZWERT")) == null));
                    z = rs.getInt("ZWERT");
                    Location loc = new Location(Bukkit.getServer().getWorld("world-"), x, y, z);
                    locs.add(loc);
                    }
                } catch (SQLException e) {
                    e.printStackTrace();
                }
               
           
           
           
            return locs;
        }
    I hope somebody can help me i'm very new to mysql in Java.
    Ole
     
  2. Offline

    timtower Administrator Administrator Moderator

    @0LUMIN4T0R Every time that you call next then you go to the next record.
    So just the next in the while is enough.
     
  3. Offline

    Scyntrus

    On line 19, the only thing that could cause an NPE is that Main.mysql has not be instantiated yet.
     
  4. Offline

    0LUMIN4T0R

    Both together helped. thx:rolleyes:
     
Thread Status:
Not open for further replies.

Share This Page