Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. package com.utils;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class Conexion {
  8. private static Connection jdbcConnection;
  9. private static String dbURL = "jdbc:mysql://localhost:3306/inventario";
  10. private static String dbUsername = "root";
  11. private static String dbPassword;
  12.  
  13. public static Connection getConnection() throws SQLException{
  14. if ( jdbcConnection == null || jdbcConnection.isClosed() ) {
  15. try {
  16. Class.forName("com.mysql.jdbc.Driver");
  17. System.out.println( "1 Connection getConnection: " );
  18. } catch (ClassNotFoundException e) {
  19. System.out.println( "Exception. Connection getConnection: " + e.getMessage());
  20.  
  21. throw new SQLException(e);
  22. }
  23. System.out.println( "2 Connection getConnection: " );
  24. jdbcConnection = DriverManager.getConnection(
  25. dbURL, dbUsername, dbPassword);
  26. }
  27. System.out.println( "3 Connection getConnection: " );
  28. return jdbcConnection;
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement