Code example for Connection

Methods: getMetaData

0
    } 
 
    public DatabaseType getDatabaseName(Connection connection) throws UnsupportedDatabaseException {
        String connectionUrl = null;
        try { 
            DatabaseMetaData metaData = connection.getMetaData();
            connectionUrl = metaData.getURL();
        } catch (SQLException e) {
            log.error("Failed to get connection url from DatabaseMetaData", e);
        } 
        DatabaseType type  =null;
        try{ 
           type =  getDatabaseType(connectionUrl.split(":")[1]);
        } 
        catch (UnsupportedDatabaseException ignored){
            //includin the check to sql server with jTDS Eg: jdbc:jtds:sqlserver://<host>:<port> 
            String[] urlElements = connectionUrl.split(":");
            if (urlElements.length > 2){
               type = getDatabaseType(urlElements[2]);
            } 
        }