public static Connection createConnection ( OntopSQLCredentialSettings settings ) throws SQLException { try { // This should work in most cases (e.g. from CLI, Protege, or Jetty) return DriverManager . getConnection ( settings . getJdbcUrl ( ) , settings . getJdbcUser ( ) , settings . getJdbcPassword ( ) ) ; } catch ( SQLException ex ) { // HACKY(xiao): This part is still necessary for Tomcat. // Otherwise, JDBC drivers are not initialized by default. if ( settings . getJdbcDriver ( ) . isPresent ( ) ) { try { Class . forName ( settings . getJdbcDriver ( ) . get ( ) ) ; } catch ( ClassNotFoundException e ) { throw new SQLException ( "Cannot load the driver: " + e . getMessage ( ) ) ; } } return DriverManager . getConnection ( settings . getJdbcUrl ( ) , settings . getJdbcUser ( ) , settings . getJdbcPassword ( ) ) ; } }
Brings robustness to some Tomcat classloading issues .