Source:
private static void initializeDatabase(String configFilePath) { InputStream in; try { in = FileUtils.openInputStream(new File(configFilePath)); StAXOMBuilder builder = new StAXOMBuilder(in); String dataSource = builder.getDocumentElement().getFirstChildWithName(new QName("DataSourceName")). getText(); OMElement databaseElement = builder.getDocumentElement().getFirstChildWithName(new QName("Database")); String databaseURL = databaseElement.getFirstChildWithName(new QName("URL")).getText(); String databaseUser = databaseElement.getFirstChildWithName(new QName("Username")).getText(); String databasePass = databaseElement.getFirstChildWithName(new QName("Password")).getText(); String databaseDriver = databaseElement.getFirstChildWithName(new QName("Driver")).getText(); BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(databaseDriver); basicDataSource.setUrl(databaseURL); basicDataSource.setUsername(databaseUser); basicDataSource.setPassword(databasePass); System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); try { InitialContext.doLookup("java:/comp/env/jdbc/WSO2AM_DB"); } catch (NamingException e) { InitialContext ic = new InitialContext(); ic.createSubcontext("java:"); ic.createSubcontext("java:/comp"); ic.createSubcontext("java:/comp/env"); ic.createSubcontext("java:/comp/env/jdbc"); ic.bind("java:/comp/env/jdbc/WSO2AM_DB", basicDataSource); } } catch (XMLStreamException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (NamingException e) { e.printStackTrace(); } }

Target:
private static void initializeDatabase(String configFilePath) throws XMLStreamException, IOException, NamingException { InputStream in; try { in = FileUtils.openInputStream(new File(configFilePath)); StAXOMBuilder builder = new StAXOMBuilder(in); String dataSource = builder.getDocumentElement().getFirstChildWithName(new QName("DataSourceName")). getText(); OMElement databaseElement = builder.getDocumentElement().getFirstChildWithName(new QName("Database")); String databaseURL = databaseElement.getFirstChildWithName(new QName("URL")).getText(); String databaseUser = databaseElement.getFirstChildWithName(new QName("Username")).getText(); String databasePass = databaseElement.getFirstChildWithName(new QName("Password")).getText(); String databaseDriver = databaseElement.getFirstChildWithName(new QName("Driver")).getText(); BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(databaseDriver); basicDataSource.setUrl(databaseURL); basicDataSource.setUsername(databaseUser); basicDataSource.setPassword(databasePass); System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); try { InitialContext.doLookup("java:/comp/env/jdbc/WSO2AM_DB"); } catch (NamingException e) { InitialContext ic = new InitialContext(); ic.createSubcontext("java:"); ic.createSubcontext("java:/comp"); ic.createSubcontext("java:/comp/env"); ic.createSubcontext("java:/comp/env/jdbc"); ic.bind("java:/comp/env/jdbc/WSO2AM_DB", basicDataSource); } } catch (XMLStreamException e) { throw new XMLStreamException("Unexpected error in processing XML"); } catch (IOException e) { throw new IOException("Error in processing the APIManagerDBConfiguration file "); } catch (NamingException e) { throw new NamingException("Error in database Username and Password"); } }