Code example for Connection

Methods: isClosed

0
        if (con == null) {
            try { 
                Class.forName("com.mysql.jdbc.Driver").newInstance();
                con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/" + dbName + "?autoReconnect=true", dbUser, dbPass);
 
                if (!con.isClosed()) {
                    logger.info("Successfully connected to " + "MySQL server using TCP/IP.");
                } 
            } catch (Exception e) {
                logger.error("Exception: " + e.getMessage());
            } 
        } 
        return con;
    } 
}