Skip to Main Content

Java Database Connectivity (JDBC)

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!

The Network adapter could not establish the connection

roymakaayDec 5 2011 — edited Oct 15 2014
Hi
When I use the following code to connect with system account it works.
but when I used it to connect with another account that has dba privilge it
gives IO Exception!
Can someone help.
import java.sql.*;
public class OraThin
{
	static String s;
public static void main(String[] args)  throws ClassNotFoundException, SQLException
{
Class.forName("oracle.jdbc.driver.OracleDriver");

         String url = "jdbc:oracle:thin:@pc_name:1521:orcl";
         Connection conn =DriverManager.getConnection(url,"user", "password");
         conn.setAutoCommit(false);
         Statement stmt = conn.createStatement();
s= "SELECT * from  table_name";
ResultSet rset = stmt.executeQuery(s);

         while (rset.next()) {



		             // Get the data from the row using the column name
		        s = rset.getString("col_1");



         }
         stmt.close();
System.out.println (s);
            }}
Exception in thread "main" java.sql.SQLException: Io exception: The Network Adap
ter could not establish the connection
        at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.ja
va:74)
        at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:1
10)
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:171)
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:227)
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:494)
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:411)
        at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:
490)
        at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:202)
        at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtensio
n.java:33)
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:465)
        at java.sql.DriverManager.getConnection(DriverManager.java:582)
        at java.sql.DriverManager.getConnection(DriverManager.java:185)
        at OraThin.main(OraThin.java:10)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 6 2012
Added on Dec 5 2011
5 comments
1,491 views