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

it contains the hostname but in a jdbc URL String format, which is not the way to get it. Is a bad practice to depend on parsing a database URL to get a hostname. What if the URL has no hostname? What if you use different databases? URLs are in different format. That's why I'm looking the hostname directly
–
RonJun 14 '11 at 8:07

1

i doubt whether u can..the reason is that the both DataSource and Connection are abstraction that dont know(dont need to know) the concept of hostname. All it knows is how to get a connection and how to call queries
–
Suraj ChandranJun 14 '11 at 8:09

Yes they are meant into that concept. But picture my problem. I'm running -pg_dumps- (Many performance reasons to do that but that's other subject), but the jboss is not always in the same machine as the databaServer, so I need to pass the hostname parameter, and using the DS is the best way I think. Cause you know for sure where the database is
–
RonJun 14 '11 at 8:15

1

@RDAM, i am not sure i get what u mean. why not just have the db details configured in files, where everyone can read it. we even had a condition where all confiugrations of all DBs where stored in a central DB
–
Suraj ChandranJun 14 '11 at 8:25

Great! I have configuration parameters inside a database. I never pictured that as another configuration parameter #Mybad. Thank u very much for your help @Suraj
–
RonJun 14 '11 at 8:33