List available data sources in EJB

  • Thread starter Alex Molochnikov
  • Start date
A

Alex Molochnikov

Is there any way to get the list of all data sources available to a session
bean? E.g. if the server (JBoss) configuration has files mssql-ds.xml and
mysql-ds.xml with jndi-name tags "MSSQLDS" and "MySqlDS" respectively, I
want to pack Strings "MSSQLDS" and "MySqlDS" into a Collection and pass it
to the client. The client will display the list of available sources and let
the user choose the database to work with.

Is it possible at all?

TIA

Alex Molochnikov
Gestalt Corporation
 
A

Alex Molochnikov

Responding to my own post:

It is possible. Here is the code:

InitialContext context = new InitialContext();
NamingEnumeration ne = context.listBindings("java:/");
while (ne.hasMore())
{
Binding b = (Binding) ne.next();
if (b.getClassName().endsWith(".DataSource"))
System.out.println(" data source = " + b.getName());
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top