Plugin not working

Discussion in 'Plugin Development' started by Licio123, Jul 21, 2014.

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

    Licio123

    I dont realy know what is hapening with this code nut I cant retrive the integer from my db look at my code
    Code:java
    1. private static Connection con;
    2. private static Statement sta;
    3. private static ResultSet result;
    4.  
    5.  
    6. public static void ConnectToDatabase(){
    7. try {
    8. con = DriverManager.getConnection("jdbc:mysql://mysql1.000webhost.com/a9755211_player", "a9755211_player", "Lucas1918");
    9. } catch (SQLException e) {
    10. e.printStackTrace();
    11. }
    12. }
    13. public int getHumanity(UUID pluuid) throws SQLException{
    14. ConnectToDatabase();
    15. try{
    16.  
    17. String query = "SELECT humanity FROM warz_player WHERE uuid=" + pluuid.toString();
    18. result = sta.executeQuery(query);
    19. result.getInt("humanity");
    20.  
    21. } catch (Exception e){
    22. e.printStackTrace();
    23. }
    24. return result.getInt("humanity");
    25. }
    26. public static int getZombies(UUID pluuid) throws SQLException{
    27. try{
    28.  
    29. String query = "SELECT zombies FROM warz_player WHERE uuid=" + pluuid.toString();
    30. result = sta.executeQuery(query);
    31.  
    32.  
    33.  
    34. } catch (Exception e){
    35. e.printStackTrace();
    36. }
    37. return result.getInt("zombies");
    38. }
    39. public int getbandits(UUID pluuid) throws SQLException{
    40. try{
    41.  
    42. String query = "SELECT bandits FROM warz_player WHERE uuid=" + pluuid.toString();
    43. result = sta.executeQuery(query);
    44.  
    45.  
    46. } catch (Exception e){
    47. e.printStackTrace();
    48. }
    49. return result.getInt("bandits");
    50. }
    51. public int getMurders(UUID pluuid) throws SQLException{
    52. try{
    53.  
    54. String query = "SELECT murders FROM warz_player WHERE uuid=" + pluuid.toString();
    55. result = sta.executeQuery(query);
    56.  
    57.  
    58. } catch (Exception e){
    59. e.printStackTrace();
    60. }
    61. return result.getInt("murders");
    62. }
     
  2. Offline

    Garris0n

    Well, first, read this and fix that connect method.
     
  3. Offline

    hintss

    While we're giving off-topic suggestions, OP should use prepared statements

    Not really helpful without showing us the NPE...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  4. Offline

    Garris0n

    I was going to save pointing that out until after he fixed the aforementioned issue. Note the cause of his NPE :p
     
  5. Offline

    hintss

    oh wow...
     
  6. Offline

    augustt198


    Just an idea... how about not posting your credentials online?
     
    hintss likes this.
  7. Offline

    mythbusterma

  8. Offline

    Licio123

    can anyone just tell me how can I get int from a database
    ?
     
  9. Offline

    hintss

    read over your code a few times, it's pretty obvious ;) (hint: what is sta equal to?)
     
  10. Offline

    Zarkopafilis

    1)
    Code:
    It should be:
    uuid=' + id.toString() + '
    
    2) Close the Result set and statement
    3)Check if the result set is not null
    4)make sure you have established a connection and every player is getting register on the database
    5)Avoid statements. Use PreparedStatements instead
    6) Docs.

    Edit: Use a new statement and result set each time. They dont get GC'd unless you close them
     
Thread Status:
Not open for further replies.

Share This Page