Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Need platform independent java code for TNS PING

1008979May 15 2013
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 12 2013
Added on May 15 2013
0 comments
598 views