ResultSet Problems...

Discussion in 'Plugin Development' started by BaconStripzMan, Dec 25, 2015.

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

    BaconStripzMan

    Hello, bukkit community. It's me once again, Bacon.

    I've decided to finally start coding my Lobby plugin for my network and I got all the code working. Except, when I use
    Code:
    if(!res.next()) {//bla bla}
    It doesn't go perform the stuff inside, even though I have an empty table?
    CODE:
    Code:
    @EventHandler
      public void onPlayerJoin(PlayerJoinEvent e) {
         Player p = e.getPlayer();
         p.sendTitle("§bBacon Network", "§eNow with more §6Bacon!");
         ResultSet res;
         try {
           res = statement.executeQuery("SELECT * FROM BaconNetwork WHERE uuid = '" + p.getUniqueId().toString() + "';");
           if(res.next() == false) {
             statement.executeUpdate("INSERT INTO BaconNetwork (`uuid`, `rank`, `coins`, `credits`, `banned`, `friends`) VALUES ('" + p.getUniqueId().toString() + "', 'Member', 0, 0, 0, 0);");
             System.out.println("Inserted info");
           }
          res.close();
         } catch (SQLException ev) {
           ev.printStackTrace();
         }
      }
     
  2. Offline

    mine-care

    Hello,
    I am not an expert but from the docs:
    So from that i understand that your table may be empty in terms of data but it will have empty rows. Thats just a thought from the top of my mind though that might not even be true :(.

    Also,
    i recomend you do the databse querry asynchronously to prevent freezes of the main thread that other than excessive lag will lead to a possible crash (if the request takes ages to complete)
    Secondly, dont use the chat color character (§). Instead prefer the enum ChatColor.
     
Thread Status:
Not open for further replies.

Share This Page