-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConexion.java
More file actions
62 lines (53 loc) · 1.66 KB
/
Copy pathConexion.java
File metadata and controls
62 lines (53 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package modelo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Dell PC
*/
public class Conexion {
private static final String DATABASE = "utilidadesdb";
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String USER = "root";
private static final String PASSWORD = "luigi009";
private static final String URL = "jdbc:mysql://localhost:3306/" + DATABASE + "?user=" + USER + "&password=" + PASSWORD + "&useSSL=false";
private Connection con;
public Conexion() {
con = null;
try {
Class.forName(DRIVER);
con = (Connection) DriverManager.getConnection(URL);
if (con != null) {
System.out.println("Conexión a la BD con éxito");
}
} catch (SQLException | ClassNotFoundException ex) {
System.err.println(ex);
}
}
/**
* Retorna la conexión a la BD
*
* @return
*/
public Connection getConnection() {
return con;
}
/**
* Permite desconectar la BD
*/
public void desconectar() {
try {
con.close();
System.exit(0);
} catch (SQLException ex) {
Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
}
}
}