Search in sources :

Example 1 with SQLBuilder

use of at.xirado.bean.data.database.SQLBuilder in project Bean by Xirado.

the class GuildManager method retrieveGuildData.

private static GuildData retrieveGuildData(long guildID) {
    String sql = "SELECT data FROM guildSettings WHERE guildID = ?";
    var query = new SQLBuilder(sql).addParameter(guildID);
    try (var rs = query.executeQuery()) {
        if (rs.next())
            return new GuildData(guildID, DataObject.fromJson(rs.getString("data")));
        return null;
    } catch (SQLException ex) {
        LOGGER.error("Could not retrieve guild data!", ex);
        return null;
    }
}
Also used : SQLBuilder(at.xirado.bean.data.database.SQLBuilder) SQLException(java.sql.SQLException)

Example 2 with SQLBuilder

use of at.xirado.bean.data.database.SQLBuilder in project Bean by Xirado.

the class GuildManager method updateGuildData.

private static void updateGuildData(long guildID, DataObject data) {
    String sql = "INSERT INTO guildSettings (guildID, data) values (?,?) ON DUPLICATE KEY UPDATE data = ?";
    try {
        String jsonString = data.toString();
        var query = new SQLBuilder(sql).addParameters(guildID, jsonString, jsonString);
        query.execute();
    } catch (SQLException exception) {
        LOGGER.error("Could not update guild data!", exception);
    }
}
Also used : SQLBuilder(at.xirado.bean.data.database.SQLBuilder) SQLException(java.sql.SQLException)

Aggregations

SQLBuilder (at.xirado.bean.data.database.SQLBuilder)2 SQLException (java.sql.SQLException)2