Search in sources :

Example 16 with Connexion

use of util.Connexion in project KaellyBot by Kaysoro.

the class Guild method setLanguage.

public synchronized void setLanguage(Language lang) {
    this.language = lang;
    Connexion connexion = Connexion.getInstance();
    Connection connection = connexion.getConnection();
    try {
        PreparedStatement preparedStatement = connection.prepareStatement("UPDATE Guild SET lang = ? WHERE id = ?;");
        preparedStatement.setString(1, lang.getAbrev());
        preparedStatement.setString(2, id);
        preparedStatement.executeUpdate();
    } catch (SQLException e) {
        Reporter.report(e);
        LOG.error(e.getMessage());
    }
}
Also used : Connexion(util.Connexion)

Example 17 with Connexion

use of util.Connexion in project KaellyBot by Kaysoro.

the class Guild method setName.

public synchronized void setName(String name) {
    this.name = name;
    Connexion connexion = Connexion.getInstance();
    Connection connection = connexion.getConnection();
    try {
        PreparedStatement preparedStatement = connection.prepareStatement("UPDATE Guild SET name = ? WHERE id = ?;");
        preparedStatement.setString(1, name);
        preparedStatement.setString(2, id);
        preparedStatement.executeUpdate();
    } catch (SQLException e) {
        Reporter.report(e);
        LOG.error(e.getMessage());
    }
}
Also used : Connexion(util.Connexion)

Example 18 with Connexion

use of util.Connexion in project KaellyBot by Kaysoro.

the class OrderUser method addToDatabase.

/**
 * Ajoute à la base de donnée l'objet si celui-ci n'y est pas déjà.
 */
public synchronized void addToDatabase() {
    if (!getOrders().containsKey(Quadruple.of(idUser, server, city, order)) && level > 0) {
        getOrders().put(Quadruple.of(idUser, server, city, order), this);
        Connexion connexion = Connexion.getInstance();
        Connection connection = connexion.getConnection();
        try {
            PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO Order_User(id_user, server_dofus, name_city, name_order, level) " + "VALUES(?, ?, ?, ?, ?);");
            preparedStatement.setString(1, String.valueOf(idUser));
            preparedStatement.setString(2, server.getName());
            preparedStatement.setString(3, city.getName());
            preparedStatement.setString(4, order.getName());
            preparedStatement.setInt(5, level);
            preparedStatement.executeUpdate();
        } catch (SQLException e) {
            Reporter.report(e, ClientConfig.DISCORD().getUserByID(idUser));
            LOG.error("addToDatabase", e);
        }
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Connexion(util.Connexion)

Example 19 with Connexion

use of util.Connexion in project KaellyBot by Kaysoro.

the class OrderUser method setLevel.

public synchronized void setLevel(int level) {
    if (level > 100)
        level = 100;
    this.level = level;
    Connexion connexion = Connexion.getInstance();
    Connection connection = connexion.getConnection();
    try {
        PreparedStatement preparedStatement;
        if (level > 0) {
            preparedStatement = connection.prepareStatement("UPDATE Order_User SET level = ?" + "WHERE name_city = ? AND name_order = ? AND id_user = ? AND server_dofus = ?;");
            preparedStatement.setInt(1, level);
            preparedStatement.setString(2, city.getName());
            preparedStatement.setString(3, order.getName());
            preparedStatement.setString(4, String.valueOf(idUser));
            preparedStatement.setString(5, server.getName());
        } else {
            preparedStatement = connection.prepareStatement("DELETE FROM Order_User " + "WHERE name_city = ? AND name_order = ? AND id_user = ? AND server_dofus = ?;");
            preparedStatement.setString(1, city.getName());
            preparedStatement.setString(2, order.getName());
            preparedStatement.setString(3, String.valueOf(idUser));
            preparedStatement.setString(4, server.getName());
        }
        preparedStatement.executeUpdate();
    } catch (SQLException e) {
        Reporter.report(e, ClientConfig.DISCORD().getUserByID(idUser));
        LOG.error("setLevel", e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Connexion(util.Connexion)

Example 20 with Connexion

use of util.Connexion in project KaellyBot by Kaysoro.

the class ChannelLanguage method addToDatabase.

public synchronized void addToDatabase() {
    if (!getChannelLanguages().containsKey(getChannelId())) {
        getChannelLanguages().put(getChannelId(), this);
        Connexion connexion = Connexion.getInstance();
        Connection connection = connexion.getConnection();
        try {
            PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO Channel_Language(id_chan, lang) VALUES(?, ?);");
            preparedStatement.setString(1, String.valueOf(getChannelId()));
            preparedStatement.setString(2, getLang().getAbrev());
            preparedStatement.executeUpdate();
        } catch (SQLException e) {
            Reporter.report(e, ClientConfig.DISCORD().getChannelByID(getChannelId()).getGuild(), ClientConfig.DISCORD().getChannelByID(getChannelId()));
            LOG.error("addToDatabase", e);
        }
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Connexion(util.Connexion)

Aggregations

Connexion (util.Connexion)24 Connection (java.sql.Connection)17 PreparedStatement (java.sql.PreparedStatement)17 SQLException (java.sql.SQLException)17 ResultSet (java.sql.ResultSet)6 IChannel (sx.blah.discord.handle.obj.IChannel)2 City (enums.City)1 Job (enums.Job)1 Language (enums.Language)1 Order (enums.Order)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 IGuild (sx.blah.discord.handle.obj.IGuild)1