package base_leslie;

//import base_leslie.InsertTable;
import java.sql.*;
/**@author Felipe*/

public class MyDBConnection {

    private String URL = "jdbc:mysql://localhost:3306/test";
    private Connection miConexion;//Variable que conecta con la base.
    
    /** Creates a new instance of MyDBConnection 
     Crea una nueva conection*/
    public MyDBConnection() { }

    
    public boolean init(){
    
       boolean temp = true;
       
       try{
       //URL de conección.
        Class.forName("com.mysql.jdbc.Driver");
        //Conectando, a través del driver JDBC...
        miConexion = DriverManager.getConnection( URL ,"root", "wk4020"); 
        }
        catch(Exception e){//Muestras los excepciones al URL
            temp = false;
            //System.out.println("Failed to get connection");
            //e.printStackTrace();
        }
       return(temp);
    }
        
    public Connection getMyConnection(){
        return miConexion;
    }
    
    public void close(ResultSet rs){
        
        if(rs != null){
            try{
               rs.close();
            }
            catch(Exception e){}
        }
    }
    
     public void close(java.sql.Statement stmt){
        
        if(stmt !=null){
            try{
               stmt.close();
            }
            catch(Exception e){}
        
        }
    }
     
  //Cierre de la coneccion.   
  public void destroy(){
  
    if(miConexion != null){
    
         try{
               miConexion.close();
            }
            catch(Exception e){}
    }
  }
    
}
