user3112427
user3112427

Reputation: 23

JDBC simple program

This is my simple JDBC program but I am not able to establish connection. The class path is set up with ojdbc6.jar.

package Demo;
import java.sql.*;

public class JdbcDemo {
    public static void main(String[] args)throws Exception {
        // TODO Auto-generated method stub
        System.out.println("hi");
        Class.forName("oracle.jdbc.driver.OracleDriver");
        System.out.println("hi1");

        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:system","scott","tiger");
    }
}

This is the output and the exception I am getting:

Exception in thread "main" java.sql.SQLRecoverableException: Io exception: The Network Adapter could not establish the connection
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:101)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:173)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:229)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:458)
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(T4CDriverExtension.java:33)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:465)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Demo.JdbcDemo.main(JdbcDemo.java:13)

Upvotes: 0

Views: 331

Answers (1)

denismathew
denismathew

Reputation: 11

Please check the following

  1. Have you started Oracle TNS Listener, if not start by lsnrctl utility.
  2. Have you put the correct port
  3. Is your hostname correct in the database server?

The issue could be any one of the above.

Upvotes: 1

Related Questions