Link to home
Start Free TrialLog in
Avatar of barnarp
barnarp

asked on

Reading Oracle database alias information

Hi,

Is there a way to read the Oracle database entry information from the tnsnames.ora file in order to populate a dropdown of databases that the user can select which one to log in to?

Regards
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Does:

    SELECT datname FROM pg_database;    

work?
Avatar of barnarp
barnarp

ASKER

I am looking for javacode.

Cannot run selects as I am not connected to the database yet.
Sorry, that's postgres as well I believe...

you will need to connect to the database to be able to get the list...

Maybe by creating a small test database, you will be able to connect to that, and then query the database for its metadata...

Tim
From this:

https://www.experts-exchange.com/questions/20781495/listing-database-names-and-table-names.html

once you connect to a database, you can apparently fire the SQL query:

     select name from v$database;

To get the list...

I have no way of testing this tho :-(
Avatar of barnarp

ASKER

Yes,

The query select name from v$database; works once you are connected. But I need a way to reed the .ora file (.ini type file) in the Oracle directory to determine which connections are on the pc.

Regards
http://www.codeproject.com/useritems/INIFile.asp

will read INI files (if it is a standard windows ini file format)

Assuming you have a local copy of the .ora file

Of course, if the database is on a remote machine, you'll have to go the other route :-)

Tim
Avatar of barnarp

ASKER

Typical .ora file entry:

CMM6.WORLD =
  (DESCRIPTION =
    (ADDRESS_LIST =
        (ADDRESS =
          (PROTOCOL = TCP)
          (Host = MP2HC203)
          (Port = 1521)
        )
    )
    (CONNECT_DATA = (SID = CMM6)
    )
  )


Not the same as ini
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Did that work then?

Cool :-)

Good luck with it!!

Tim
Avatar of barnarp

ASKER

I got it running in the command line, but don't know how to get it working in JSP yet?