Repository navigation
Expand file tree
/
Copy pathConexion.java
More file actions
51 lines (44 loc) · 1.78 KB
/
Copy pathConexion.java
File metadata and controls
51 lines (44 loc) · 1.78 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Connection;
import ModelClass.ListClass;
import java.sql.Connection;
import java.sql.DriverManager;
/**
*
* @author AlexJPZ
*/
public class Conexion extends ListClass {
private String db = "system_ventas";
private String user = "root";
private String password = "hacker.net";
private String urlMysql = "jdbc:mysql://localhost:3310/";
// private String urlMysql = "jdbc:mysql://localhost/" + db + "?SslMode=none";
//private String urlSql = "jdbc:sqlserver://localhost:1433;databaseName=" + db + ";integratedSecurity=true;";
private Connection conn = null;
//1. Cambie el driver por la siguiente ruta
//Class.forName("com.mysql.cj.jdbc.Driver");
//2. Para el problema de la zona horaria en la parte de la definicion de la url puse lo siguiente:
//private String url = "jdbc:mysql://localhost/"+db+"?useTimezone=true&serverTimezone=UTC";
public Conexion() {
try {
// obtenemos el driver de para mysql
Class.forName("com.mysql.jdbc.Driver");
//conn = DriverManager.getConnection(this.urlMysql, this.user, this.password);
conn = DriverManager.getConnection(this.urlMysql + this.db, this.user, this.password);
// Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
// conn =DriverManager.getConnection(urlSql);
if (conn != null) {
System.out.println("Conexión a la base de datos " + this.db + "...... Listo ");
}
} catch (Exception ex) {
System.out.println("Error : " + ex);
}
}
public Connection getConn() {
return conn;
}
}