Given a context file:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/scum">
<Resource name="jdbc/MyApp"
auth="Container"
type="javax.sql.DataSource"
username="username"
password="password"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://mysql.server.com:8080/DB"
validationQuery="select 1"
maxActive="20"
maxIdle="2"/>
</Context>
I can get the url of the Resource using the following code:
Context xmlContext = (Context) ic.lookup("java:comp/env");
DataSource dataSource = (DataSource) xmlContext.lookup("jdbc/MyApp");
Connection connection = dataSource.getConnection();
String url = connection.getMetaData().getURL();
However, if the connection fails, there is no metadata and unfortunately, no url. How can I get the url without making a connection to the DataSource?