Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. package Config; //Paquete de conexion
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import javax.swing.JOptionPane;
  7.  
  8. /**
  9. *
  10. * @author Ivan Ledesma
  11. */
  12. public class Conexion {
  13. public static final String URL= "jdbc:mysql://localhost:3306/empresa?zeroDateTimeBehavior=convertToNull";
  14. public static final String USERNAME= "root";
  15. public static final String PASSWORD= "";
  16. public static Conexion instance;
  17. private Connection cnn;
  18.  
  19. //obtener la conexion
  20. private Conexion() {
  21. try{
  22. Class.forName("com.mysql.jdbc.Driver");
  23. cnn = DriverManager.getConnection(URL,USERNAME, PASSWORD);
  24. }catch(ClassNotFoundException ex){
  25. JOptionPane.showMessageDialog(null, "Error en la Conexion : "+ex.getMessage());
  26. }catch (SQLException ex) {
  27. JOptionPane.showMessageDialog(null, "Error en la Conexion : "+ex.getMessage());
  28. }
  29. }
  30.  
  31. public synchronized static Conexion getConexion(){
  32. if(instance == null){
  33. instance = new Conexion();
  34. }
  35. return instance;
  36. }
  37.  
  38. public Connection getCnn() {
  39. return cnn;
  40. }
  41.  
  42. public void cerrarConexion(){
  43. instance = null;
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement