Wednesday, August 24, 2016

Check DB connection to an Oracle DBMS from a remote machine

Using SQLPLUS:

Execute following command in a command line:
sqlplus "<DB_USERNAME>/<DB_PASSWORD>@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=<HOST_NAME>)(Port=1521))(CONNECT_DATA=(SID=<SID>)))"


You will be able to login to the database in the remote machine, if connection is successful.

Using Weblogic DBPing utility

Execute following command in a command line:
java -classpath <WL_HOME>/<WL_SERVER>/server/lib/weblogic.jar utils.dbping ORACLE_THIN <DB_USERNAME> <DB_PASSWORD> <HOST_NAME>:<DB_PORT>:<SID>

You will get following message if connection is successful.
**** Success!!! ****

You can connect to the database in your app using:

  java.util.Properties props = new java.util.Properties();
  props.put("user", "<DB_USERNAME>");
  props.put("password", "<DB_PASSWORD>");
  java.sql.Driver d =
    Class.forName("oracle.jdbc.OracleDriver").newInstance();
  java.sql.Connection conn =
    Driver.connect("jdbc:oracle:thin:@<HOST_NAME>:<DB_PORT>:<SID>", props);




References:

  •  https://docs.oracle.com/cd/E13222_01/wls/docs/techstart/dbping.html
  • http://javaeesupportpatterns.blogspot.sg/2011/03/network-adapter-could-not-establish.html
  • http://dba.stackexchange.com/questions/13075/how-to-use-sqlplus-to-connect-to-an-oracle-database-located-on-another-host-with


~~~


No comments: