Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Config; //Paquete de conexion
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import javax.swing.JOptionPane;
- /**
- *
- * @author Ivan Ledesma
- */
- public class Conexion {
- public static final String URL= "jdbc:mysql://localhost:3306/empresa?zeroDateTimeBehavior=convertToNull";
- public static final String USERNAME= "root";
- public static final String PASSWORD= "";
- public static Conexion instance;
- private Connection cnn;
- //obtener la conexion
- private Conexion() {
- try{
- Class.forName("com.mysql.jdbc.Driver");
- cnn = DriverManager.getConnection(URL,USERNAME, PASSWORD);
- }catch(ClassNotFoundException ex){
- JOptionPane.showMessageDialog(null, "Error en la Conexion : "+ex.getMessage());
- }catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, "Error en la Conexion : "+ex.getMessage());
- }
- }
- public synchronized static Conexion getConexion(){
- if(instance == null){
- instance = new Conexion();
- }
- return instance;
- }
- public Connection getCnn() {
- return cnn;
- }
- public void cerrarConexion(){
- instance = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement