Q:

Class for MySQL and SQLite

I'm programming a Bukkit plugin, a server for the "Minecraft" game. I don't know how to write SQL, just some syntax. 
I am looking for Java class to access MySQL and SQLite. The plugin will use only one database at a time, set in configuration file, MySQL or SQLite.
I've found this:
import java.io.*;
import java.sql.*;
import java.util.logging.*;
import org.bukkit.plugin.*;

public class Db {
    private final Plugin plugin;
    private final String url;
    private Logger log;
    Connection connection = null;  
    ResultSet resultSet = null;  
    Statement statement = null;  

    public Db(final Plugin plugin, final String host, final String database,
            final String user, final String password) {
        this.plugin = plugin;
        url = "jdbc:mysql://" + host + "/" + database + "?user=" + user
                + "&password=" + password;
        log = plugin.getServer().getLogger();
        initDriver("com.mysql.jdbc.Driver");
    }

    public Db(final Plugin plugin, final String filePath) {
        this.plugin = plugin;
        url = "jdbc:sqlite:" + new File(filePath).getAbsolutePath();
        log = plugin.getServer().getLogger();
        initDriver("org.sqlite.JDBC");
    }

    private void initDriver(final String driver) {
        try {
            Class.forName(driver);
        } catch (final Exception e) {
            log.severe("Database driver error:" + e.getMessage());
        }
    }

    public int resultInt(ResultSet result, int column) {
        if (result == null)
            return 0;
        try {
            result.next();
            int integer = result.getInt(column);
            result.close();

            return integer;
        } catch (SQLException e) {
            log.severe("Database result error: " + e.getMessage());
        }
        return 0;
    }

    public String resultString(ResultSet result, int column) {
        if (result == null)
            return null;
        try {
            result.next();
            String string = result.getString(column);
            result.close();
            return string;
        } catch (SQLException e) {
            log.severe("Database result error: " + e.getMessage());
        }
        return null;
    }

    public ResultSet query(final String query) {
        return query(query, false);
    }

    public ResultSet query(final String query, final boolean retry) {
        try {
            final Connection connection = DriverManager.getConnection(url);
            final PreparedStatement statement = connection
                    .prepareStatement(query);
            if (statement.execute())
                return statement.getResultSet();
        } catch (final SQLException e) {
            final String msg = e.getMessage();
            log.severe("Database query error: " + msg);
            if (retry && msg.contains("_BUSY")) {
                log.severe("Retrying query...");

                plugin.getServer().getScheduler()
                        .scheduleSyncDelayedTask(plugin, new Runnable() {
                            @Override
                            public void run() {

                                query(query);
                            }
                        }, 20);
            }
        }
        return null;
    }
}

But I don't know how to close the connection and statement.
In this code I must use
base = new Db(this, getDataFolder() + File.separator + "SQLite.db");

But using that code creates multiple threads and that gives me errors. I must find a class where I can close the connection and statement. I am learning Java for only few weeks and I don't know much.

A:

ok... I have new work code. I edited old :)
import java.io.*;
import java.sql.*;

public class Db {
    private final String url;
    ResultSet resultSet = null;
    Statement statement = null;
    final String driver;
    String user = "";
    String database = "";
    String password = "";
    String port = "";
    String host = "";
    Connection c = null;

    public Db(String Host, String db, String username, String password) {
        this.host = Host;
        this.database = db;
        this.user = username;
        this.password = password;
        url = "jdbc:mysql://" + host + "/" + database + "?user=" + user
                + "&password=" + password;
        driver = ("com.mysql.jdbc.Driver");
    }

    public Db(String filePath) {
        url = "jdbc:sqlite:" + new File(filePath).getAbsolutePath();
        driver = ("org.sqlite.JDBC");
    }

    public Connection open() {
        try {
            Class.forName(driver);
            this.c = DriverManager.getConnection(url);
            return c;
        } catch (SQLException e) {
            System.out
                    .println("Could not connect to MySQL/SQLite server! because: "
                            + e.getMessage());
        } catch (ClassNotFoundException e) {
            System.out.println("JDBC Driver not found!");
        }
        return this.c;
    }

    public boolean checkConnection() {
        if (this.c != null) {
            return true;
        }
        return false;
    }

    public Connection getConn() {
        return this.c;
    }

    public void closeConnection(Connection c) {
        c = null;
    }
}

