Guest User

Untitled

a guest
Feb 23rd, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. public Connection MySQLConnection(String user, String pass, String db_name) {
  2. try {
  3. Class.forName("com.mysql.jdbc.Driver");
  4. conexion = DriverManager.getConnection("jdbc:mysql://localhost:3306/" + db_name, user, pass);
  5. System.out.println("Conectado");
  6. // JOptionPane.showMessageDialog(null, "Se ha iniciado la conexión con el servidor de forma exitosa");
  7. } catch (ClassNotFoundException ex) {
  8. Logger.getLogger(conexion.class.getName()).log(Level.SEVERE, null, ex);
  9. } catch (SQLException ex) {
  10. JOptionPane.showMessageDialog(null, ex.getMessage());
  11. }
  12. return conexion;
  13. }
  14. public void closeConnection() {
  15. try {
  16. conexion.close();
  17. // JOptionPane.showMessageDialog(null, "Se ha finalizado la conexión con el servidor");
  18. } catch (SQLException ex) {
  19. Logger.getLogger(conexion.class.getName()).log(Level.SEVERE, null, ex);
  20. }
  21. }
Add Comment
Please, Sign In to add comment