-
Notifications
You must be signed in to change notification settings - Fork 1
/
Conexion.java
43 lines (37 loc) · 1.11 KB
/
Conexion.java
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
/*
* 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 universidad.modelo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.JOptionPane;
/**
*
* @author pascu
*/
public class Conexion {
private final String base = "universidad3";
private final String url="jdbc:mysql://localhost:3306/"+base;
private final String user="pascu";
private final String pass="";
private Connection con;
public Connection getConnection()
{
if(con==null)
{
try
{
Class.forName("org.mariadb.jdbc.Driver");
con = (Connection)DriverManager.getConnection(url, user, pass);
}
catch (SQLException |ClassNotFoundException e)
{
JOptionPane.showMessageDialog(null, "Error al conectarse");
}
}
return con;
}
}