Guest User

Untitled

a guest
Nov 15th, 2016
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. package conexion;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. import javax.swing.JOptionPane;
  8.  
  9. public class Conexion {
  10.  
  11. Connection con = null;
  12. String db = null;//para el nombre de la base de datos
  13.  
  14. public Conexion() {
  15. super();
  16. }
  17.  
  18. public Conexion(String db) {
  19. super();
  20. this.db = db;
  21. }
  22.  
  23. public Connection getConexion(){
  24.  
  25. String user = "Ejemplo";
  26. String pass = "Ejemplo";
  27. String url = "jdbc:mysql://localhost:3306/ejemplo?serverTimezone=Europe/Madrid";
  28.  
  29. try{
  30. Class.forName("com.mysql.cj.jdbc.Driver");
  31. con=DriverManager.getConnection(url, user, pass);
  32. JOptionPane.showMessageDialog(null, "ConexiΓ³n establecida");
  33.  
  34. }catch (ClassNotFoundException e) {
  35. JOptionPane.showMessageDialog(null, "Cod error 01");
  36. } catch (SQLException e) {
  37. JOptionPane.showMessageDialog(null, "Cod error 02");
  38. }
  39. return con;
  40. }
  41.  
  42. }
Add Comment
Please, Sign In to add comment