import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

public class DBManager {

    Connection conexion;
    Statement sentencia;

    DBManager(){
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (Exception ex) {
            System.out.println("Error al cargar el driver: "+ex.getMessage());
        }

        try {
            conexion = DriverManager.getConnection("jdbc:mysql://localhost/RCBD", "root", "soyroot");
            sentencia = (Statement) conexion.createStatement();
        } catch (SQLException ex) {
            System.out.println("Error al crear conexión: "+ex.getMessage());
        }
    }

    public boolean Query(String query){
        boolean ret;

        try {
            sentencia.execute(query);
            ret = true;
        } catch (SQLException ex) {
            ret = false;
            System.out.println("Error al ejecutar query: "+ex.getMessage());
        }
        return ret;
    }

    public void Close(){
        try {
            conexion.close();
            sentencia.close();
        } catch (SQLException ex) {
            System.out.println("Error al cerrar conexión: "+ex.getMessage());
        }

    }
}
