Results 1 to 3 of 3
  1. #1
    matpj is offline Member
    Join Date
    Sep 2008
    Posts
    42
    Rep Power
    0

    Default errors when trying to connect to database

    Hi all,

    I am trying to connect to a database within a class:
    Java Code:
    import java.sql.*;
    
    class SimpleOraJava {
      public static void main(String args[]) throws SQLException {
        DriverManager.registerDriver(
          new oracle.jdbc.driver.OracleDriver()
        );
        String serverName = "nikuuat";
        int port = 1521;
        String user = "niku";
        String password = "niku";
        String SID = "nikuuat";
        String URL = "jdbc:oracle:thin:@" + serverName + ":" + port + ":" + SID;
        Connection conn = DriverManager.getConnection(URL, user, password);
        String SQL = "SELECT DSTI_PROJ_REF FROM NIKU.ODF_CA_PROJECT";
        Statement stat = conn.createStatement();
        ResultSet rs = stat.executeQuery(SQL);
        while (rs.next()) {
          System.out.println(
            rs.getInt(1) +
            "\t" +
            rs.getString(2)
          );
        }
        stat.close();
        conn.close();
      }
    }
    when I try to run this I get the following error:
    Java Code:
    run:
    Exception in thread "main" java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
            at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
            at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
            at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:334)
            at oracle.jdbc.ttc7.TTC7Protocol.handleIOException(TTC7Protocol.java:3695)
            at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:352)
            at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:362)
            at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:536)
            at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:328)
            at java.sql.DriverManager.getConnection(DriverManager.java:582)
            at java.sql.DriverManager.getConnection(DriverManager.java:185)
            at SimpleOraJava.main(SimpleOraJava.java:30)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 2 seconds)
    i'm not sure what to do, can anybody advise?

    thanks in advance,
    Matt

  2. #2
    matpj is offline Member
    Join Date
    Sep 2008
    Posts
    42
    Rep Power
    0

    Default

    can anyone help me?

  3. #3
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    7

    Default

    Not too familiar with Oracle or this particular JDBC driver, but if I was coming at this new, I would:
    - double tripple check the URL format -- I know they're different drivers and the format isn't standard, but compared to the format for connecting to MySQL or connecting to SQL Server, the format you have above looks quite odd
    - does your DB log anything useful? (like a "permission denied to client XXX" message)
    - can you connect from the same machine to the DB but via a different means, e.g. an interactive SQL client?
    - is Java even getting as far as sending anything down the network? - if the DB is on a different box, install a packet sniffer and check that some data is actually being sent across the network and some coming back in? if something is going out but not coming back in, what does a packet sniffer on the DB machine pick up? any firewall in the way of the two that you should be aware of?
    Last edited by neilcoffey; 12-18-2008 at 01:07 AM. Reason: forgot sth

Similar Threads

  1. Replies: 0
    Last Post: 11-06-2008, 10:07 AM
  2. Replies: 3
    Last Post: 09-18-2008, 04:07 PM
  3. connect JDBC to offline database
    By nancyhung in forum JDBC
    Replies: 1
    Last Post: 04-12-2008, 12:04 AM
  4. Using JDBC to connect to ORACLE database
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-10-2008, 12:27 PM
  5. Problem to connect Database
    By Swamipsn in forum NetBeans
    Replies: 1
    Last Post: 08-07-2007, 08:13 AM

Posting Permissions

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