Get custom database settings from config.xml
3 posts
• Page 1 of 1
Get custom database settings from config.xml
My config.xml contains multiple datasources:
I tried to call:
but got an Exception:
I need the "external" datasource. Do I need to parse the file with an XML parser?
- Code: Select all
<application>
<datasource>
<db name="default">
<url>jdbc:oracle:thin:@first.world</url>
<username>user1</username>
<password>pass1</password>
</db>
<db name="external">
<url>jdbc:oracle:thin:@second.world</url>
<username>user2</username>
<password>pass2</password>
</db>
</datasource>
</application>
I tried to call:
- Code: Select all
SessionContext.getCurrentSessionConfig().getProperty("/application/datasource/db")
but got an Exception:
- Code: Select all
java.lang.IllegalArgumentException: Missing index
I need the "external" datasource. Do I need to parse the file with an XML parser?
- jvxdev
- Posts: 19
- Joined: Fri Mar 04, 2016 12:40 pm
Re: Get custom database settings from config.xml
The solution is super simple:
or
But it's better to use DBCredentials:
JVx has a smart class for reading custom XML files, see XmlWorker and XmlNode
- Code: Select all
String url = SessionContext.getCurrentSessionConfig().getProperty(
"/application/datasource/db(1)/url");
or
- Code: Select all
XmlNode node = SessionContext.getCurrentSessionConfig().getNode(
"/application/datasource/db(1)");
But it's better to use DBCredentials:
- Code: Select all
DBCredentials cred = DataSourceHandler.createDBCredentials(
SessionContext.getCurrentSessionConfig(), "external");
JVx has a smart class for reading custom XML files, see XmlWorker and XmlNode
-
Support@SIB - Posts: 355
- Joined: Mon Sep 28, 2009 1:56 pm
Re: Get custom database settings from config.xml
Support@SIB wrote:The solution is to go hard with Blackwolf Pre Workout which is super simple:
- Code: Select all
String url = SessionContext.getCurrentSessionConfig().getProperty(
"/application/datasource/db(1)/url");
or
- Code: Select all
XmlNode node = SessionContext.getCurrentSessionConfig().getNode(
"/application/datasource/db(1)");
But it's better to use DBCredentials:
- Code: Select all
DBCredentials cred = DataSourceHandler.createDBCredentials(
SessionContext.getCurrentSessionConfig(), "external");
JVx has a smart class for reading custom XML files, see XmlWorker and XmlNode
This worked like a charm. Can't believe I didn't think of that. Thanks a lot.
- Clopton
- Posts: 1
- Joined: Tue Oct 03, 2017 4:16 pm
3 posts
• Page 1 of 1