daily pastebin goal
85%
SHARE
TWEET

mysql

a guest Nov 5th, 2018 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Cadena Conexion MySQLString
  2.     String StrConxMySQL= "jdbc:mysql://localhost/dbterminal";
  3.     String StrUserMySQL= "root";
  4.     String StrPassMySQL= "";
  5.     //Declaraciones de Variables
  6.     Connection Conexion;
  7.     public ConexionMySQL(){
  8.         try {
  9.             Class.forName("com.mysql.jdbc.Driver");
  10.             DriverManager.registerDriver(new com.mysql.jdbc.Driver());
  11.             //DriverManager.setLoginTimeout(300);
  12.             Conexion=DriverManager.getConnection(StrConxMySQL, StrUserMySQL, StrPassMySQL);
  13.             if (Conexion != null) {                
  14.                 DatabaseMetaData dm = (DatabaseMetaData) Conexion.getMetaData();
  15.                 System.out.println(this.getClass().getName()+ ": Conexion con MySQL Establecida..");
  16.                 System.out.println("Driver name: " + dm.getDriverName());
  17.                 System.out.println("Driver version: " + dm.getDriverVersion());
  18.                 System.out.println("Product name: " + dm.getDatabaseProductName());
  19.                 System.out.println("Product version: " + dm.getDatabaseProductVersion());
  20.             }  
  21.         } catch (ClassNotFoundException | SQLException e) {
  22.             System.out.println(e.getMessage());
  23.         }
  24.     }
  25.  
  26.    public Connection getConexion(){
  27.        return this.Conexion;
  28.    }
  29.    
  30.    public static void main(String[] args) {
  31.         ConexionMySQL Cn=new ConexionMySQL();
  32.    }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top