Home » Developer & Programmer » JDeveloper, Java & XML » Network Adapter could not establish connection
Network Adapter could not establish connection [message #91118] Mon, 15 April 2002 19:07 Go to next message
Siddhartha Mehta
Messages: 3
Registered: April 2002
Junior Member
I am trying for a simple connection between Java and Oracle and I have been trying since last couple of days but does not work. I have pasted tnsnames.ora, litener.ora, Test.java and the exception I get. Could anyone please look into and help me if everything looks fine. Thanks for the help.

My hostname: shail
Port: 1521
SID: ORACLE

Thanks Siddhartha

tnsnames.ora
# C:ORACLEORA81NETWORKADMINTNSNAMES.ORA Configuration File:c:OracleOra81networkadmintnsnames.ora
# Generated by Oracle Net8 Assistant

EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
ORACLE_SHAIL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = shail)(PORT = 1521))
)
(CONNECT_DATA =
(SID = ORACLE)(SERVER = DEDICATED)
)
)

listener.ora

# C:ORACLEORA81NETWORKADMINLISTENER.ORA Configuration File:c:OracleOra81networkadminlistener.ora
# Generated by Oracle Net8 Assistant

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = shail)(PORT = 1521))
)
)
(DESCRIPTION =
(PROTOCOL_STACK =
(PRESENTATION = GIOP)
(SESSION = RAW)
)
(ADDRESS = (PROTOCOL = TCP)(HOST = shail)(PORT = 2481))
)
)

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = c:OracleOra81)
(PROGRAM = extproc)
)
)

LISTENER =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = ORACLE))
(ADDRESS = (PROTOCOL = TCP)(HOST = shail)(PORT = 1521))
)

sid_list_LISTENER =
(sid_list =
(sid_desc =
(sid_name = ORACLE)
(ORACLE_HOME = c:OracleOra81)
)
)

Test.java

import java.sql.*;

class Test {
public static void main (String args [[]]) throws SQLException {

// Load Oracle driver
try {
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());

System.out.println("Before Connection");
// Connect to the local database

Connection conn =
DriverManager.getConnection ("jdbc:oracle:thin:@shail:1521:ORACLE",
"scott", "tiger");
System.out.println("After Connection");

// Query the date

Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("select sysdate from dual");

// Print the name out

while (rset.next ())
System.out.println (rset.getString (1));
}
catch(Exception ioe)
{
ioe.printStackTrace();
}
}
}

Error Message

Before Connection
java.sql.SQLException: The Network Adapter could not establish the connection
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:407)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:152)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:214)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:193)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Test.main(Test.java:13)
Re: Network Adapter could not establish connection [message #91242 is a reply to message #91118] Thu, 13 June 2002 11:27 Go to previous messageGo to next message
Jay Herrick
Messages: 1
Registered: June 2002
Junior Member
Make sure the host name of your database server resolves correctly, ether through DNS or your hosts file. That's what did it for me!
Re: Network Adapter could not establish connection [message #109497 is a reply to message #91118] Thu, 24 February 2005 21:08 Go to previous message
Ajit Kumar
Messages: 2
Registered: August 2002
Junior Member
How we establish the connection of printing with the help of java.
I mean what is the coding of Print button that when we click the print button then it gives me a print.
Previous Topic: Binding array type from java code
Next Topic: jdbc-thin client thread problem
Goto Forum:
  


Current Time: Mon Nov 25 19:06:14 CST 2024