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

import java.sql.*;
import java.util.Vector;

/**
 *
 * @author jose
 */
public class DBAdm {

    private Connection con;

    /**
     * Establece conexion con la base de datos.
     **/
    public void openDb() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/memoria", "memoria", "memoria");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void closeDb() {
        try {
            con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public boolean obtenerUsuario(String query) {
        String resultado = "";
        try {
            Statement stmt = con.createStatement();
            ResultSet rsltUsuario = stmt.executeQuery(query);
            rsltUsuario.next();
            resultado = rsltUsuario.getString("user");
            stmt.close();
            if (resultado.length() == 0) {
                return false;
            } else {
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;

    }
}
