Miller
Miller

Reputation: 491

Using a JNDI datasource can I get the connection string from it?

I have my application on Tomcat with a JNDI datasource. I need to access the connection string from it. Is there a way to do that in my application?

Upvotes: 3

Views: 2163

Answers (1)

Ernesto Campohermoso
Ernesto Campohermoso

Reputation: 7371

You can try the following:

DataSource ds ...
Connection conn = ds.getConnection();
DatabaseMetadata dbmd = conn.getMetaData();
System.out.println(dbmd.getURL());

You can get more info of DataBaseMetadata chedk this:

http://docs.oracle.com/javase/6/docs/api/java/sql/DatabaseMetaData.html

Upvotes: 5

Related Questions