Get URL Value Before DataSource Connection is Made

Viewed 268

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?

1 Answers

DataSource is just a interface,you can't get anything. So you can debug DataSource to check what actually the implement class it is.

Related