HikariCP guide

Discussion in 'Spigot Plugin Development' started by MadMaxCookie, Jun 28, 2016.

  1. Hello guide me if there is wrong to what I'm trying to do, please point it out to me this is my first time to use hikaricp

    so this is my loadPlayer method.
    Code (Java):
    public void loadPlayer(Player p) {
        Bukkit.getScheduler().runTaskAsynchronously(this, new Runnable() {
            public void run() {
                try(Connection connection = getConnection();
                     PreparedStatement insert = connection.prepareStatement(INSERT);
                     PreparedStatement select = connection.prepareStatement(SELECT)) {
                    insert.setString(1, p.getUniqueId().toString());
                    insert.setString(2, p.getName());
                    insert.setString(4, p.getName());
                    select.setString(1, p.getUniqueId().toString());
                    ResultSet result = select.executeQuery();
                    if(result.getString("count") == null) {
                        insert.setInt(3, 0);
                    }else {
                        times.put(p.getAddress(), result.getInt("count"));
                }catch(SQLException e) {
    Code (Java):
    private static final String INSERT = "INSERT INTO Accounts VALUES(?,?,?) ON DUPLICATE KEY UPDATE name=?";
    private static final String SELECT = "SELECT count FROM Accounts WHERE uuid=?";
    • Winner Winner x 1
    • Optimistic Optimistic x 1
  2. yes what's wrong with copied ? I'm trying to understand every code on it and copy first to see what else happens if it's implemented, that's why I'm here to ask where I messed ?

    and also like what @ md_5 said how not to help : ....
  3. #4 _Cory_, Jun 28, 2016
    Last edited: Jun 28, 2016
  4. Kinda like a threapools <3 too bad Spigot uses a cached thread pool in bukkit runnables instead of fixed.
  5. First, I recommend you looking at these links:
    Okay then, so what is the problem? Are you getting any errors?
  6. Here is an example from my tutorial. You have to make sure that you close your resources (connection, statement and result set) also in case of an exception (in the finally clause or use try-with-resources) and you have to check if (result.next()).
  7. A Connection pool is a 'collection' of multiple connections, so that if you have a connection that's busy doing some big queries, it won't slow down the server as there are other connections that will take over and execute your next queries.
  8. No, it's creating a pool of connections - Those connections won't be any faster just because your using HikariCP
  9. True... my mistake.