-
Notifications
You must be signed in to change notification settings - Fork 0
/
conexion.java
37 lines (33 loc) · 1.12 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
import java.sql.*;
import javax.swing.JOptionPane;
public class conexion
{
private String nombreBd = "mydb";
private String usuario = "root";
private String password = "bebe09102018";
private String url="jdbc:mysql://localhost:3306/"+nombreBd+"?useUnicode=true6use"+"JDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&"+ "severTimeZone=UTC";
Connection conn=null;
public conexion()
{
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
conn=DriverManager.getConnection(url, usuario, password);
if(conn!=null)
{
JOptionPane.showMessageDialog(null,"CONEXIÓN EXITOSA...","ÉXITO...",JOptionPane.INFORMATION_MESSAGE);
}
}
catch(ClassNotFoundException e)
{
JOptionPane.showMessageDialog(null, "CONEXIÓN FALLIDA, ClassNotFoundException: " + e.getMessage(),"CONEXIÓN FALLIDA...",JOptionPane.INFORMATION_MESSAGE);
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(null,"CONEXIÓN FALLIDA, SQLException: " + e.getLocalizedMessage(),"CONEXIÓN FALLIDA...",JOptionPane.INFORMATION_MESSAGE);
}
}
public static void main(String[] args)
{
}
}