// Imports
import java.sql.*;

// Database Class
public class Database {

    // Variables
    private Connection connection;
    private Statement statement;

    // Setup Method
    public void setup (String url, String username, String password) throws SQLException {
        // Set Variables
        this.connection = DriverManager.getConnection(url, username, password);
        this.statement = this.connection.createStatement();
    }

    // Is Setup Method
    public boolean isSetup () {
        // Return Setup
        return this.connection != null && this.statement != null;
    }

    // Query Method
    public String query (String sql) {
        // Catch Errors
        try {
            // Execute Query
            ResultSet results = this.statement.executeQuery(sql);
            ResultSetMetaData resultsMetaData = results.getMetaData();
            // Create Result
            StringBuilder result = new StringBuilder();
            // Create Header
            for (int counter = 1; counter <= resultsMetaData.getColumnCount(); counter++) {
                result.append(resultsMetaData.getColumnName(counter));
                if (counter != resultsMetaData.getColumnCount()) {
                    result.append(" - ");
                }
            }
            result.append("\n");
            // Create Content
            while (results.next()) {
                for (int counter = 1; counter <= resultsMetaData.getColumnCount(); counter++) {
                    result.append(results.getString(counter));
                    if (counter != resultsMetaData.getColumnCount()) {
                        result.append(" - ");
                    }
                }
                result.append("\n");
            }
            // Return Result
            return result.toString();
        } catch (Exception exception) {
            // Return Result
            return "Query Invalid";
        }
    }

}