Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2375
  • Last Modified:

how to get TNSNAMES entries list using java to access oracle?

hi everybody,
  I try to use oracle oci driver to connect oracle database with java servlet, but at first, I try to get the local machines' all TNSNAMES entries from \orahome\transname.ora, I implemented it by parsing this file, but as you know, it is not good, because different machine has different orahome,anybody have a good idea to get those entries and put them into a JComboBox?
thanks
0
lisayan
Asked:
lisayan
  • 2
1 Solution
 
hasselstromkCommented:
You could check the operating system, if NT get ORACLE_HOME via registry, then parse file.  If UNIX, get ORACLE_HOME via env variable, then parse file.

Hope this helps.
Keith Hasselstrom
0
 
lisayanAuthor Commented:
thanks, hasselstromk, could you tell me how get ORACLE_HOME via registry using java?
0
 
hasselstromkCommented:
lisayan,

OK...what a lessoned learned.  I had some time to kill so I think I can help out.  I found a package that allows access to the registry.  I downloaded the zip file.  But the package is called JNI Registry.  I can return email you a copy.  My email is kmhasselstrom@tasc.com.  After setting up the class names it was very easy to traverse the registry.  

The code to get my Oracle home on my windows 2000 box is posted below.  I have several Oracle installs so you may want to write some code to read all the Oracle homes and get all the values.  Then look for several TNS names etc....

If you get a java.lang.path error try this url for help:
http://www.visi.com/~gyles19/fom-serve/cache/95.html

Hope this helps...
Keith

import java.util.*;
import javax.naming.*;
import com.ice.jni.registry.*;

public class WinRegAccess extends Object {


public static void main(String[] args) throws RegistryException{

 RegistryKey reg = Registry.HKEY_LOCAL_MACHINE.openSubKey("SOFTWARE");
 RegistryKey reg2 = reg.openSubKey("ORACLE");
 RegistryKey reg3 = reg2.openSubKey("HOME2");

 System.out.println(reg3.getStringValue("ORACLE_HOME"));

}

}
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now