开发者

Get the hostname from a DataSource class

开发者 https://www.devze.com 2023-03-13 00:40 出处:网络
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开发者_JAVA百科 get the

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开发者_JAVA百科 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


Once you have the DatabaseMetaData, just call the getURL() method which should contain the hostname like so:

dataSource.getConnection().getMetaData().getURL();
0

精彩评论

暂无评论...
验证码 换一张
取 消