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
barnarpAsked:
Who is Participating?
 
TimYatesCommented:
Oooooh!

Look what I found:

http://www.orsweb.com/downloads/source/447.html

and

http://www.orsweb.com/downloads/source/495.html

the second one apparently "...offers more than existing solutions have. It encapsulates the alias entries in this library for access via Enumeration or specified alias string. Methods are provided to build a connect string or access the protocol, host, port and sid separately"

:-D
0
 
TimYatesCommented:
Does:

    SELECT datname FROM pg_database;    

work?
0
 
barnarpAuthor Commented:
I am looking for javacode.

Cannot run selects as I am not connected to the database yet.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
TimYatesCommented:
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
0
 
TimYatesCommented:
From this:

http://www.experts-exchange.com/Databases/Oracle/Q_20781495.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 :-(
0
 
barnarpAuthor Commented:
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
0
 
TimYatesCommented:
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
0
 
barnarpAuthor Commented:
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
0
 
TimYatesCommented:
Did that work then?

Cool :-)

Good luck with it!!

Tim
0
 
barnarpAuthor Commented:
I got it running in the command line, but don't know how to get it working in JSP yet?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.