Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Join Date
    Oct 2014
    Posts
    12

    Unanswered: error trying to connect with program in java with oracle database, on oracle linux

    I have oracle linux 6.5, Oracle Database 11g Enterprise Edition Release 11.2.0.1.0

    I wrote a test program in NetBeans to connect to the oracle database
    during the start of the program I get the error below

    why?

    SQL * Plus connects to the data without any problem also
    Oracle SQL Developer connects to the data without a problem

    library project poloczzora added ojdbc6.jar

    ( scott
    the user is active

    I log on to his account from sql plus and Oracle SQL Developer )



    program:


    package poloczzora;

    import java.sql.*;

    public class Poloczzora {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) throws Exception {


    try {

    Class.forName("oracle.jdbc.OracleDriver");
    } catch (java.lang.ClassNotFoundException e) {
    System.err.print("Error: ClassNotFoundException");
    }

    Connection conn = DriverManager.getConnection
    ("jdbcracle:thin:@//localhost:1521/orcl", "scott", "tiger");
    }

    }






    Exception in thread "main" java.sql.SQLException: The Network Adapter could not establish the connection
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnecti on.java:412) at oracle.jdbc.driver.T4CConnection.logon(T4CConnecti on.java:412)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnecti on.java:412)
    calConnection.java:531)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnect ion.java:221)
    at oracle.jdbc.driver.T4CDriverExtension.getConnectio n(T4CDriverExtension.java:32)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriv er.java:503)
    at java.sql.DriverManager.getConnection(DriverManager .java:571)
    at java.sql.DriverManager.getConnection(DriverManager .java:215)
    at poloczzora.Poloczzora.main(Poloczzora.java:41)
    Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
    at oracle.net.nt.ConnStrategy.execute(ConnStrategy.ja va:359)
    at oracle.net.resolver.AddrResolution.resolveAndExecu te(AddrResolution.java:422)
    at oracle.net.ns.NSProtocol.establishConnection(NSPro tocol.java:672)
    at oracle.net.ns.NSProtocol.connect(NSProtocol.java:3 53)
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnec tion.java:1042)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnecti on.java:301)
    ... 7 more
    Caused by: java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(Abstrac tPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress( AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractP lainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.j ava:392)
    at java.net.Socket.connect(Socket.java:579)
    at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.ja va:141)
    at oracle.net.nt.ConnOption.connect(ConnOption.java:1 23)
    at oracle.net.nt.ConnStrategy.execute(ConnStrategy.ja va:337)
    ... 12 more
    Java Result: 1
    BUILD SUCCESSFUL (total time: 14 seconds)

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    below worked/works for me


    bcm@bcm-laptop:~$ cat Conn.java
    import java.sql.*;
    class Conn {
    public static void main (String[] args) throws Exception
    {
    Class.forName ("oracle.jdbc.OracleDriver");

    Connection conn = DriverManager.getConnection
    ("jdbcracle:thin:@//localhost:1521/v112", "scott", "tiger");
    // @//machineNameort/SID, userid, password
    try {
    Statement stmt = conn.createStatement();
    try {
    ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION");
    try {
    while (rset.next())
    System.out.println (rset.getString(1)); // Print col 1
    }
    finally {
    try { rset.close(); } catch (Exception ignore) {}
    }
    }
    finally {
    try { stmt.close(); } catch (Exception ignore) {}
    }
    }
    finally {
    try { conn.close(); } catch (Exception ignore) {}
    }
    }
    }
    bcm@bcm-laptop:~$ javac Conn.java
    bcm@bcm-laptop:~$ export CLASSPATH=/u01/app/oracle/product/11.2.0/dbhome_1/owb/wf/lib/ojdbc14.jar:.
    bcm@bcm-laptop:~$ java Conn
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE 11.2.0.1.0 Production
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    bcm@bcm-laptop:~$
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Oct 2014
    Posts
    12
    I think my settings are identical, but do not mix me with the base only gives an error










    Quote Originally Posted by Robert24 View Post
    I have oracle linux 6.5, Oracle Database 11g Enterprise Edition Release 11.2.0.1.0

    I wrote a test program in NetBeans to connect to the oracle database
    during the start of the program I get the error below

    why?

    SQL * Plus connects to the data without any problem also
    Oracle SQL Developer connects to the data without a problem

    library project poloczzora added ojdbc6.jar

    ( scott
    the user is active

    I log on to his account from sql plus and Oracle SQL Developer )



    program:


    package poloczzora;

    import java.sql.*;

    public class Poloczzora {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) throws Exception {


    try {

    Class.forName("oracle.jdbc.OracleDriver");
    } catch (java.lang.ClassNotFoundException e) {
    System.err.print("Error: ClassNotFoundException");
    }

    Connection conn = DriverManager.getConnection
    ("jdbcracle:thin:@//localhost:1521/orcl", "scott", "tiger");
    }

    }






    Exception in thread "main" java.sql.SQLException: The Network Adapter could not establish the connection
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnecti on.java:412) at oracle.jdbc.driver.T4CConnection.logon(T4CConnecti on.java:412)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnecti on.java:412)
    calConnection.java:531)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnect ion.java:221)
    at oracle.jdbc.driver.T4CDriverExtension.getConnectio n(T4CDriverExtension.java:32)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriv er.java:503)
    at java.sql.DriverManager.getConnection(DriverManager .java:571)
    at java.sql.DriverManager.getConnection(DriverManager .java:215)
    at poloczzora.Poloczzora.main(Poloczzora.java:41)
    Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
    at oracle.net.nt.ConnStrategy.execute(ConnStrategy.ja va:359)
    at oracle.net.resolver.AddrResolution.resolveAndExecu te(AddrResolution.java:422)
    at oracle.net.ns.NSProtocol.establishConnection(NSPro tocol.java:672)
    at oracle.net.ns.NSProtocol.connect(NSProtocol.java:3 53)
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnec tion.java:1042)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnecti on.java:301)
    ... 7 more
    Caused by: java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(Abstrac tPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress( AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractP lainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.j ava:392)
    at java.net.Socket.connect(Socket.java:579)
    at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.ja va:141)
    at oracle.net.nt.ConnOption.connect(ConnOption.java:1 23)
    at oracle.net.nt.ConnStrategy.execute(ConnStrategy.ja va:337)
    ... 12 more
    Java Result: 1
    BUILD SUCCESSFUL (total time: 14 seconds)

  4. #4
    Join Date
    Oct 2014
    Posts
    12
    I think my settings are identical, but do not mix me with the base only gives an error

  5. #5
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    what happens when you run my code against your DB?
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  6. #6
    Join Date
    Oct 2014
    Posts
    12
    Quote Originally Posted by anacedent View Post
    what happens when you run my code against your DB?
    added to the library in the NetBeans project, the path to the app app/oracle/product/11.2.0/dbhome_1/owb/wf/lib/ojdbc14.jar

    Exception in thread "main" 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: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:414)
    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(DriverManager .java:571)
    at java.sql.DriverManager.getConnection(DriverManager .java:215)
    at poloczzora.Poloczzora.main(Poloczzora.java:44)
    at oracle.jdbc.driver.DatabaseError.throwSqlException (DatabaseError.java:112)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 1 second)

  7. #7
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    post results from OS command below

    cat /etc/hosts
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  8. #8
    Join Date
    Oct 2014
    Posts
    12
    Quote Originally Posted by anacedent View Post
    post results from OS command below

    cat /etc/hosts

    127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

  9. #9
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >Oracle SQL Developer connects to the data without a problem
    by default SQL Developer uses JDBC:thin to connect; which indicates that the listener & database are properly configured & a bug exists within your Java code.

    Have you properly established CLASSPATH variable?
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  10. #10
    Join Date
    Oct 2014
    Posts
    12
    Quote Originally Posted by anacedent View Post
    >Oracle SQL Developer connects to the data without a problem
    by default SQL Developer uses JDBC:thin to connect; which indicates that the listener & database are properly configured & a bug exists within your Java code.

    Have you properly established CLASSPATH variable?

    echo $PATH
    /usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/oracle/app/oracle/product/11.2.0/dbhome_1/bin



    variables

    $ORACLE_BASE
    /home/oracle/app/oracle

    $ORACLE_HOME
    /home/oracle/app/oracle/product/11.2.0/dbhome_1

    $ORACLE_SID
    orcl


    in file oratab orcl:/home/oracle/app/oracle/product/11.2.0/dbhome_1:N

  11. #11
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    Interesting response; NOT!

    did you actually READ the question in my previous post?
    >Have you properly established CLASSPATH variable?

    CLASSPATH variable is required & used by JDBC:thin to complete SQL*net connection request.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  12. #12
    Join Date
    Oct 2014
    Posts
    12
    What is the value, added in the CLASSPATH ?

  13. #13
    Join Date
    Oct 2014
    Posts
    12
    CLASSPATH is empty

    set to ojdbc6.jar ?

  14. #14
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    find / -name odbc\*jar -ls 2>/dev/null

    post results from above
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  15. #15
    Join Date
    Oct 2014
    Posts
    12
    Quote Originally Posted by anacedent View Post
    find / -name odbc\*jar -ls 2>/dev/null

    post results from above

    done in the terminal command as user oracle and root
    and there were no results

Posting Permissions

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