Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.utils;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class Conexion {
- private static Connection jdbcConnection;
- private static String dbURL = "jdbc:mysql://localhost:3306/inventario";
- private static String dbUsername = "root";
- private static String dbPassword;
- public static Connection getConnection() throws SQLException{
- if ( jdbcConnection == null || jdbcConnection.isClosed() ) {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- System.out.println( "1 Connection getConnection: " );
- } catch (ClassNotFoundException e) {
- System.out.println( "Exception. Connection getConnection: " + e.getMessage());
- throw new SQLException(e);
- }
- System.out.println( "2 Connection getConnection: " );
- jdbcConnection = DriverManager.getConnection(
- dbURL, dbUsername, dbPassword);
- }
- System.out.println( "3 Connection getConnection: " );
- return jdbcConnection;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement