@@ -0,0 +1,2817 @@
+package com.simplyian.easydb;%0A%0Aimport com.mysql.jdbc.jdbc2.optional.MysqlDataSource;%0Aimport java.sql.*;%0Aimport java.util.logging.Level;%0Aimport java.util.logging.Logger;%0Aimport org.apache.commons.dbutils.QueryRunner;%0Aimport org.apache.commons.dbutils.ResultSetHandler;%0Aimport org.apache.commons.dbutils.handlers.ScalarHandler;%0A%0A/**%0A * Database stuff. MySQL sucks.%0A */%0Apublic final class Database %7B%0A    private final ResultSetHandler SCALAR_HANDLER = new ScalarHandler();%0A%0A    private final EasyDB plugin;%0A%0A    private final MysqlDataSource source;%0A%0A    public Database(EasyDB plugin, String user, String pass, String host, int port, String database) %7B%0A        this.plugin = plugin;%0A%0A        source = new MysqlDataSource();%0A        source.setUser(user);%0A        source.setPassword(pass);%0A        source.setServerName(host);%0A        source.setPort(port);%0A        source.setDatabaseName(database);%0A    %7D%0A%0A    /**%0A     * Attempts to connect to the database to check if the database credentials%0A     * are valid.%0A     *%0A     * @return%0A     */%0A    public boolean isValid() %7B%0A        try %7B%0A            return source.getConnection() != null;%0A        %7D catch (SQLException ex) %7B%0A            return false;%0A        %7D%0A    %7D%0A%0A    /**%0A     * Executes a database update.%0A     *%0A     * @param query%0A     */%0A    public void update(String query, Object... params) %7B%0A        QueryRunner run = new QueryRunner(source);%0A        try %7B%0A            if (params == null) %7B%0A                run.update(query);%0A            %7D else %7B%0A                run.update(query, params);%0A            %7D%0A        %7D catch (SQLException ex) %7B%0A            plugin.getLogger().log(Level.SEVERE, %22Could not run database query '%22 + query + %22'!%22, ex);%0A        %7D%0A    %7D%0A%0A    /**%0A     * Executes a database query.%0A     *%0A     * @param %3CT%3E%0A     * @param query%0A     * @param handler%0A     * @param params%0A     * @return%0A     */%0A    public %3CT%3E T query(String query, ResultSetHandler%3CT%3E handler, Object... params) %7B%0A        QueryRunner run = new QueryRunner(source);%0A        try %7B%0A            if (params != null) %7B%0A                return run.query(query, handler, params);%0A            %7D else %7B%0A                return run.query(query, handler);%0A            %7D%0A        %7D catch (SQLException ex) %7B%0A            plugin.getLogger().log(Level.SEVERE, %22Could not execute database query '%22 + query + %22'!%22, ex);%0A        %7D%0A        return null;%0A    %7D%0A%0A    /**%0A     * Gets a value from the database. The column desired must be the first.%0A     *%0A     * @param query%0A     * @param def The default value to return if the value is null.%0A     * @param params%0A     * @return%0A     */%0A    public Object get(String query, Object def, Object... params) %7B%0A        Object ret = query(query, SCALAR_HANDLER, params);%0A        if (ret == null) %7B%0A            return def;%0A        %7D%0A        return ret;%0A    %7D%0A%7D%0A

Add database class