Results 1 to 6 of 6
  1. #1
    choloboy is offline Member
    Join Date
    Jan 2012
    Posts
    1
    Rep Power
    0

    Default Connecting to Oracle 10g Database

    Hi everyone, i have this piece of code i am using to connect to my database and i keep getting this error...
    java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
    at oracle.jdbc.driver.DatabaseError.throwSqlException (DatabaseError.java:112)
    at oracle.jdbc.driver.DatabaseError.throwSqlException (DatabaseError.java:146)
    at oracle.jdbc.driver.DatabaseError.throwSqlException (DatabaseError.java:255)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnecti on.java:387)
    at oracle.jdbc.driver.PhysicalConnection.<init>(Physi calConnection.java:441)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnect ion.java:165)
    at oracle.jdbc.driver.T4CDriverExtension.getConnectio n(T4CDriverExtension.java:35)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriv er.java:801)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at DbC.main(DbC.java:11)

    Any idea what it means and what can be done to fix it?
    Thanks a lot!

    Here is my code...
    Java Code:
    import java.sql.Connection;  
    import java.sql.DriverManager;  
    import java.sql.ResultSet;  
    import java.sql.Statement;  
    import java.sql.SQLException;
     
    public class DbC {  
        public static void main(String[] args) {  
            try {  
                DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());  
                Connection connection = DriverManager.getConnection(  
                        "jdbc:oracle:thin:@localhost:1521:orcl", "username", "password");  
      
                Statement statement = connection.createStatement();  
                ResultSet resultSet = statement.executeQuery("SELECT * FROM students");  
                while (resultSet.next()) {  
                    System.out.println("students:"  
                            + resultSet.getString("*"));  
                }  
            } catch (Exception e) {  
                e.printStackTrace();  
            }  
        }  
    }
    localhost, username and password were changed for my personal privacy...

    Again thanks for any help!

  2. #2
    HowardHyde is offline Member
    Join Date
    Jan 2012
    Posts
    12
    Rep Power
    0

    Default Re: Connecting to Oracle 10g Database

    Use oracle.jdbc.OracleDriver instead of oracle.jdbc.driver.OracleDriver.
    Is the driver file (i.e. ojdbc6.jar) in your CLASSPATH?
    Is your database running?
    Is the database listener running (and listening)?
    Can you connect to this database with the same account via sqlplus?

    Let me know which one of these suggestions worked (or didn't).

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,040
    Rep Power
    20

    Default Re: Connecting to Oracle 10g Database

    It'll be one of the last ones.
    The driver is there and is attempting to connect, otherwise there wouldn't be any "oracle.jdbc.driver..." in the stack trace, and you'd get a different exception anyway.

  4. #4
    HowardHyde is offline Member
    Join Date
    Jan 2012
    Posts
    12
    Rep Power
    0

    Default Re: Connecting to Oracle 10g Database

    The driver may or may not be the problem in this case, but since oracle.jdbc.driver.OracleDriver has been deprecated for a while, I think it would be be best to use the correct one oracle.jdbc.OracleDriver to be sure.
    See:
    ClassNotFoundException: oracle.jdbc.driver.OracleDriver
    Apache Tomcat 6.0 (6.0.35) - JNDI Datasource HOW-TO

  5. #5
    bams is offline Member
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

    Default Re: Connecting to Oracle 10g Database

    User ojdbc.jar and instead of the following line

    Java Code:
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    Use the below line :

    Java Code:
    Class.forName ("oracle.jdbc.OracleDriver");

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,040
    Rep Power
    20

    Default Re: Connecting to Oracle 10g Database

    That's a good point.
    The OP didn't say what versions of anything they were using...

Similar Threads

  1. Help me connecting java and oracle
    By Waseem Kaleem in forum JDBC
    Replies: 11
    Last Post: 12-07-2009, 03:38 PM
  2. Connecting jsp.net with Oracle.
    By crxuz in forum JDBC
    Replies: 0
    Last Post: 07-08-2009, 10:17 AM
  3. problems with connecting to Oracle DB in NetBeans
    By m16k2002 in forum Web Frameworks
    Replies: 6
    Last Post: 03-25-2009, 10:14 AM
  4. Error While connecting to Oracle thru JAVA
    By javaneed in forum Advanced Java
    Replies: 1
    Last Post: 08-11-2007, 10:05 PM
  5. Replies: 0
    Last Post: 08-07-2007, 07:01 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •