Is there a way to get the hostname from the DataSource class in java? I mean, I have a DataSource object (DS), which is annotated to get the Jboss datasource. Anyway, I want to get the hostname used in that DS.
Debugging, i can see it this way: I get the Connection from DS, then I get the DataSourceMetaData and inside of that the is something called Protocol Connection which have the hostname, but I don't know how to get it.
Anyone here knows how? or another way to get the hostname? Thanks in advance. Kind regards, RDAM
Use the DataSource. getConnection method to obtain the connection. You can use one of the following forms of the getConnection method: getConnection(); getConnection(String user, String password);
In this case, billingDB is the logical name that is given to the BasicDataSource object ds . The subcontext jdbc is reserved for logical names to be bound to DataSource objects, so jdbc will always be the first part of a logical name for a data source.
A DataSource object is the representation of a data source in the Java programming language. In basic terms, a data source is a facility for storing data. It can be as sophisticated as a complex database for a large corporation or as simple as a file with rows and columns.
Once you have the DatabaseMetaData, just call the getURL() method which should contain the hostname like so:
dataSource.getConnection().getMetaData().getURL();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With