0

Can someone tell me if there's anything wrong with this SQL query?

My server keeps losing connection when trying to receive the info. There is like 50,000 logs on the SQL though which it creates in like 5 days. Maybe it's pumping them too fast?

package io.xeros.sql.leaderboard;

import io.xeros.content.leaderboards.LeaderboardEntry;
import io.xeros.content.leaderboards.LeaderboardType;
import io.xeros.sql.DatabaseManager;
import io.xeros.sql.SqlQuery;
import io.xeros.util.Misc;

import java.sql.*;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

public class LeaderboardGetAll implements SqlQuery<List<LeaderboardEntry>> {

    private final LeaderboardType type;

    public LeaderboardGetAll(LeaderboardType type) {
        this.type = type;
    }

    @Override
    public List<LeaderboardEntry> execute(DatabaseManager context, Connection connection) throws SQLException {
        ArrayList<LeaderboardEntry> entries = new ArrayList<>();

        PreparedStatement leaders = connection.prepareStatement("SELECT * FROM leaderboards "
                + "INNER JOIN display_names on display_names.login_name = leaderboards.username"
                + " where type = " + type.ordinal()
                + " ORDER BY date DESC, amount DESC"
        );

        ResultSet rs = leaders.executeQuery();
        while (rs.next()) {
            String loginName = rs.getString("username");
            String displayName = rs.getString("display_name");
            int amount = rs.getInt("amount");
            int type = rs.getInt("type");
            Date date = rs.getDate("date");
            entries.add(new LeaderboardEntry(LeaderboardType.values()[type], Misc.formatPlayerName(loginName), displayName, amount, date.toLocalDate().
                    atStartOfDay()));
        }
        return entries;
    }
}

These are my Hikari settings:

config.setMaximumPoolSize(64);
config.setLeakDetectionThreshold(48);
config.setConnectionTimeout(5000);
config.setIdleTimeout(60000);
config.setMinimumIdle(20);
config.setValidationTimeout(3000);
config.setMaxLifetime(500000);

This is the first error I get:

20:37:14.697 [database-manager-66] ERROR io.xeros.sql.DatabaseManager - An error occurred while trying to execute a query, database= DatabaseCredentials{url='jdbc:mysql://198.12.12.226/ashihama_server?autoReconnect=true&useSSL=false&serverTimezone=America/Chicago', username='ashihama_server'}, query=io.xeros.model.cycleevent.impl.LeaderboardUpdateEvent$$Lambda$844/0x000000080115b840@5b23bd72
java.sql.SQLException: Connection reset
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
    at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
    at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1003)
    at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
    at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
    at io.xeros.sql.leaderboard.LeaderboardGetAll.execute(LeaderboardGetAll.java:32)
    at io.xeros.model.cycleevent.impl.LeaderboardUpdateEvent.lambda$runUpdate$1(LeaderboardUpdateEvent.java:72)
    at io.xeros.sql.DatabaseManager.executeImmediate(DatabaseManager.java:141)
    at io.xeros.sql.DatabaseManager.lambda$exec$2(DatabaseManager.java:116)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: java.net.SocketException: Connection reset
Abra
  • 19,142
  • 7
  • 29
  • 41

0 Answers0