import java.sql.*;
import java.util.logging.*;
import java.io.IOException;
import java.util.*;

    /**
	 * ...
	 * @author PainKiller
	 */

public class DBManager
{

    private String host = "jdbc:mysql://mysql-env-5856194.jelasticloud.com/db_user";
    private String username = "db_user";
    private String password = "pass12345";
    private String driver = "com.mysql.jdbc.Driver";
    
    public List drivers;
    private ArrayList rowValues = new ArrayList();

    private final static String getData = "SELECT name FROM  `vk_users`";

    public Connection createConnection() throws IOException, ClassNotFoundException, SQLException
    {
        try
        {
            DriverManager.registerDriver((Driver)Class.forName(driver).newInstance());
        } catch (InstantiationException ex)
        {
            Logger.getLogger(DBManager.class.getName()).log(Level.SEVERE, null, ex);
             rowValues.add(ex.toString());
        } catch (IllegalAccessException ex)
        {
            Logger.getLogger(DBManager.class.getName()).log(Level.SEVERE, null, ex);
            rowValues.add(ex.toString());
        }
        Connection connection = DriverManager.getConnection(host, username, password);
        //drivers = Collections.list(DriverManager.getDrivers());
        System.out.println("CONNECTION: " + connection);
        return connection;
    }

    public ArrayList<String> getResults()
    {
        ResultSet rs;
        try
        {
            Statement statement = createConnection().createStatement();
            rs = statement.executeQuery(getData);
            while (rs.next())
            {
                rowValues.add(rs.getString(1));
            }

        } catch (IOException ex)
        {
            Logger.getLogger(DBManager.class.getName()).log(Level.SEVERE, null, ex);
            rowValues.add(ex.toString());
        } catch (ClassNotFoundException ex)
        {
            Logger.getLogger(DBManager.class.getName()).log(Level.SEVERE, null, ex);
             rowValues.add(ex.toString());
        } catch (SQLException ex)
        {
            ex.printStackTrace();
             rowValues.add(ex.toString());
        }
        return rowValues;
    }

}
