Error in connecting Oracle Database from JAVA application!!!
ManojCApr 14 2012 — edited Apr 16 2012Hi,
I am trying to connect to the Oracle11g database server from the client machine using JAVA eclipse. I have installed the oracle client in the client machine. Once i try to execute the below code it was throwing below error:
public class Dbconnect {
public static void main (String[] args)throws Exception {
try {
Class.forName ("oracle.jdbc.driver.OracleDriver");
String connectString = "jdbc:oracle:thin:@<IP Address>:1521:orcl";
OracleDriver drivers = new OracleDriver();
System.out.println(drivers);
Connection connection = null;
connection = (OracleConnection)DriverManager.getConnection(connectString,"ADMIN", "admin");
System.out.println(connection);
System.out.println("Connected to the database");
//
Error:
java.sql.SQLException: The Network Adapter could not establish the connection
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:412)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:531)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:221)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at DBConnect.main(DBConnect.java:15)
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:359)
at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:422)
at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:672)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:237)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1042)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:301)
... 7 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:141)
at oracle.net.nt.ConnOption.connect(ConnOption.java:123)
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:337)
... 12 more
I am unable to connect using sqlplus as well ORA-12560: TNS:protocol adapter error
Please advise me on how to resolve this issue..
Thanks