0

I'm trying to get User and URL from DataSource in java without being connect to database but I cant figured out how to do that.

I'm using the JdbcTemplate and the only option I see to do that is with the code:

    jdbcTemplate.getDataSource().getConnection().getMetaData().getURL();
    jdbcTemplate.getDataSource().getConnection().getMetaData().getUserName();

But, I recivied the error when I try to ".getConnection()":

javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:DataSource

There is another way?

Myphre
  • 1
  • I think once you're at the level of `JdbcTemplate` you don't have easy access to that information. You can inspect whatever provides the `JdbcTemplate`, probably. What are you trying to do with that information? It seems like this might be an [XY problem](https://xyproblem.info). – Joachim Sauer Nov 09 '21 at 15:16
  • If it's Hikari you can cast to `HikariDataSource`, for tomcat pool see https://stackoverflow.com/questions/29253895/how-to-get-username-from-connection-pool-declaration-at-runtime – Ori Marko Nov 09 '21 at 15:21

0 Answers0