Development Assistance MySQL help

Discussion in 'Plugin Help/Development/Requests' started by quinster08, Aug 15, 2015.

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

    quinster08

    Hello, why does this prints the column 3 times??:
    Code:
    public static String getRank(Player p){
            openConnection();
             try{                 
                     PreparedStatement sql = connection.prepareStatement("SELECT rank FROM `player_rank` WHERE player=?;");
                    
                     sql.setString(1, p.getName());
                     ResultSet result = sql.executeQuery();
                     result.next();
                     rank = result.getString("rank");   
                     Bukkit.broadcastMessage(rank);
                     sql.close();
                     result.close();
             }catch(Exception e1){
                e1.printStackTrace();
             }finally{
                closeConnection();
             }
            return rank;
    
        }
     
  2. Offline

    Lolmewn

    Because you call this method 3 times I guess?
     
  3. Offline

    pie_flavor

    @quinster08 I gotta say, this kinda defeats the purpose of a prepared statement. The idea is to use one statement a lot instead of rewriting it many times.
     
    mine-care likes this.
Thread Status:
Not open for further replies.

Share This Page