Search This Blog

Friday, December 28, 2012

Simple setup of TNS

Simple setup of TNS

You have multiple oracle home installed in your pc! One from Oracle Client that you installed, one from Oracle Express edition database and one from oracle workflow that you installed few months back. Now you are not sure which TNSNAMES.ora is being used or should be used. The situation sounds pretty similar... isn't it? Lets try this and get rid of the dilemma!

TNS Entry:
DEV = (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=dev.domain.ee)(PORT=1567)))(CONNECT_DATA=(SID=sdev1)(server=dedicated)))

I prefer to use oracle home from Oracle Client. In my case this is
C:\OraHome_1

So I have added the above TNS entry in tnsnames.ora file
C:\OraHome_1\network\ADMIN\TNSNAMES.ORA
Now let's cehck the existing status of my connectivity by executing tnsping:

Java Hashtable Example

import java.util.*;
public class MainClass {
  public static void main(String args[]) {
    Hashtable columnValues = new Hashtable();
    columnValues.put("Tokyo", "Japan");
    columnValues.put("Beijing", "China");
    columnValues.put("Bangkok", "Thailand");
    String city = "Beijing";
    String country = (String) columnValues.get(city);
    if (country != null)
      System.out.println(city + " is located in " + country);  //Beijing is located in China
    else
      System.out.println(city + " is not located in the hashtable");
  }
}