Connection con; String url = "jdbc:mysql://localhost:3306/bd_ventas?serverTimezone=EST5EDT"; String user = "root"; String pass = "123456"; public Connection Conexion() { try { Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection(url, user, pass); System.out.println("Conexion exitosa"); } catch (Exception e) { System.out.println("Error conexion"); } return con; } //otra forma de conexion------------------------- private Statement consulta = null; private ResultSet data = null; String bd = "compras"; String driver = "com.mysql.cj.jdbc.Driver"; String user = "root"; String password = "123456"; String url = "jdbc:mysql://localhost/" + bd + "?useTimezone=true&serverTimezone=UTC"; Connection con = null; public int MAXROW = 5; //metodo para abrir la conexion public void con() { try { Class.forName(driver);//cargamos el driver registramos con = DriverManager.getConnection(url, user, password); System.out.println("Conexion exitosa..ok"); this.consulta = con.createStatement(); //inicializamos el objeto Statement para SQL } catch (Exception e) { System.out.println("Eror de Conexion " + e.getMessage()); } } //metodo para cerrar la conexion public void desconectar() { try { if (con != null) { this.con.close(); } } catch (Exception e) { System.out.println("Error de desconexion " + e.getMessage()); } }