Advertisement
max_wadaka

conexion XML

Jun 10th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. package xml;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class Conexion {
  8.  
  9.     private static String servidor ="jdbc:mysql://localhost";
  10.     private static String user="root";
  11.     private static String pass="";
  12.     private static String driver="com.mysql.jdbc.Driver";
  13.     private static Connection Conexion;
  14.    
  15.    
  16.    
  17.     public Conexion(String base){
  18.         try{
  19.             if(base!=null){
  20.                 servidor= servidor + "/"+base;
  21.             }
  22.             Class.forName(driver);
  23.             Conexion=DriverManager.getConnection(servidor, user, pass);
  24.         } catch(ClassNotFoundException | SQLException e){
  25.             System.out.println("fallo de conexion con la base de datos");
  26.            
  27.         }
  28.     }
  29.     public Connection getConnection(){
  30.        
  31.         return Conexion;
  32.     }  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement