Results 1 to 2 of 2
  1. #1
    Muntasir is offline Member
    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    Default Re: Tnsping of some sorts

    Hi, I am able to ping server /ip address. but unable to ping some TNS entry.
    There is one way to ping TNS entry using System command, but that will make my code platform dependent. i want platform independent code.. need code help for TNS Ping to database server.. here are my code:
    ---Code for server / Ip address ping:---------

    package DBM;

    import java.io.IOException;
    import java.net.InetAddress;
    import java.net.UnknownHostException;
    import java.util.ArrayList;
    import oracle.net.TNSAddress.*;



    public class PingServer
    {
    public static void main(String[] args)
    {
    System.out.println(" Server Pinging Starts...");

    ArrayList<String> list=new ArrayList<String>();
    list.add("g5u0660c.atlanta.hp.com");
    list.add("g1u1675c.austin.hp.com");
    list.add("gvu1785.atlanta.hp.com");
    list.add("10.130.14.109");
    list.add("10.130.0.173");
    list.add("DESCRIPTION = (SDU = 32768) (enable = broken) (LOAD_BALANCE = yes) (ADDRESS = (PROTOCOL = TCP)(HOST = gvu1515.atlanta.hp.com)(PORT = 1525))(ADDRESS = (PROTOCOL = TCP)(HOST = gvu1785.atlanta.hp.com)(PORT = 1525)");
    list.add("IDSENGI");
    //This Ipadd variable is used to convert the arraylist into String
    String ipadd="";

    try
    {
    for(String s: list)
    {
    ipadd=s;
    // InetAddress is class.in this class getByName()is used to take only string parameter.
    InetAddress inet = InetAddress.getByName(ipadd);
    //InetAddress inet1 =InetAddress.getAllByName("IDESENGP");
    System.out.println("Sending Ping Request to " + ipadd);
    //in InetAddress call IsReachabe(3000)method is used to ping the server IP and if ping is successfully then return true otherwise false.
    //IsReachable()take time in millisecond and return type is boolean.

    System.out.println("Host is reachable: "+inet.isReachable(3000));
    }
    System.out.println("Server Pinging program is working fine........");

    }
    catch (UnknownHostException e)
    {
    System.err.println("Host does not exists");
    }
    catch (IOException e)
    {
    System.err.println("Error in reaching the Host");
    }

    }
    }


    ----Code for TNS ping using system host----

    package DBM;

    import java.io.*;

    public class doscmd
    {
    public static void main(String args[])
    {
    try
    {
    Process p=Runtime.getRuntime().exec("cmd /c tnsping IDSENGP");
    p.waitFor();
    BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line=reader.readLine();
    while(line!=null)
    {
    System.out.println(line);
    line=reader.readLine();
    }

    }
    catch(IOException e1) {}
    catch(InterruptedException e2) {}

    System.out.println("Done");
    }
    }
    ---
    The above two codes are working absolutely fine... but need TNS ping program is platform dependent..we need to deploy it in both windows, unix...
    Please help.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default Re: Tnsping of some sorts

    Please don't hijack a 2 year old post. I have moved your post to its own thread
    http://www.java-forums.org/content/113-forum-rules.html

Similar Threads

  1. Create a function that sorts an arraylist of objects
    By Stavrosgr in forum New To Java
    Replies: 2
    Last Post: 12-03-2012, 06:33 PM
  2. Elementary Sorts
    By tabchas in forum New To Java
    Replies: 8
    Last Post: 06-14-2011, 12:50 AM
  3. Tnsping of some sorts
    By mac in forum New To Java
    Replies: 1
    Last Post: 01-23-2010, 03:47 PM
  4. Topological Sorts
    By Emily in forum Advanced Java
    Replies: 1
    Last Post: 04-03-2008, 04:39 PM
  5. Topological Sorts
    By Emily in forum New To Java
    Replies: 0
    Last Post: 03-27-2008, 12:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •