Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Willian Cueva
Added: Dec 16, 2020 7:40 PM
Views: 8
Tags: no tags
  1.  
  2. import com.mysql.jdbc.Connection;
  3. import com.mysql.jdbc.Statement;
  4. import java.util.logging.Level;
  5. import java.util.logging.Logger;
  6. import java.sql.DriverManager;
  7. import java.sql.SQLException;
  8.  
  9. /*
  10.  * To change this license header, choose License Headers in Project Properties.
  11.  * To change this template file, choose Tools | Templates
  12.  * and open the template in the editor.
  13.  */
  14.  
  15. /**
  16.  *
  17.  * @author Willian
  18.  */
  19. public class ConexionBDD {
  20.     Connection cn;
  21.    
  22.     public Connection conexion(){
  23.         try {
  24.             Class.forName("com.mysql.jdbc.Driver");
  25.             cn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/sistema","root","root");
  26.             System.out.println("se realizo exitosamente la coneccion :D");
  27.         } catch (ClassNotFoundException | SQLException ex) {
  28.             Logger.getLogger(ConexionBDD.class.getName()).log(Level.SEVERE, null, ex);
  29.         }
  30.         return cn;
  31.     }
  32.    
  33.     Statement creaStatement(){
  34.         throw new UnsupportedOperationException("no soportado");
  35.     }
  36.    
  37. }
  38.