Solved

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

Posted on 2001-06-20
3
2,167 Views
Last Modified: 2013-11-24
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
Comment
Question by:lisayan
  • 2
3 Comments
 

Accepted Solution

by:
hasselstromk earned 50 total points
ID: 6210704
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
 

Author Comment

by:lisayan
ID: 6211462
thanks, hasselstromk, could you tell me how get ORACLE_HOME via registry using java?
0
 

Expert Comment

by:hasselstromk
ID: 6211974
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now