Advertisement
yacel100

DbConnection.java

Aug 28th, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. import java.sql.Connection;
  2.  
  3. // datos de la conexion a la base de datos
  4. import java.sql.DriverManager;
  5. public class DbConnection {  
  6.     static String bd = "tienda";  
  7.     static String login = "root";  
  8.     static String password = "";  
  9.     static String url = "jdbc:mysql://localhost/" + bd;  
  10.     Connection conn = null;
  11.    
  12.     //realizando la conexion a la base de datos
  13.     public DbConnection() {      
  14.         try {        
  15.             Class.forName("com.mysql.jdbc.Driver");
  16.             conn = DriverManager.getConnection(url, login, password);
  17.             System.out.println("CONEXION A LA BASE DE DATOS "+bd+" FUE EXITOSA");
  18.         }
  19.         catch(Exception e)
  20.         {
  21.            
  22.             System.out.println("NO SE PUEDE CONECTAR");
  23.         }
  24.     }
  25.    
  26.     //OBTENER CONEXION
  27.     public Connection getConnection(){
  28.         return conn;
  29.     }
  30.     // DESCONECCION DE LA BASE DE DATOS
  31.     public void desconectar(){
  32.         conn = null;
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement