10 Replies Latest reply: Jun 20, 2013 2:40 AM by user10839503 RSS

    Unable to connect to oracle database using os authentication?

    user10839503

      Hi,

       

      I am trying to connect to oracle database using os authentication through jdbc.

       

      I have oracle 10g installed on solaris sparc 32 bit.

       

      Following is the code for jdbc connection :-

       

      String url = "jdbc:oracle:thin:@oracleserver.mydomain.com:5521:dbja"

      Driver driver = new oracle.jdbc.OracleDriver();

      DriverManager.registerDriver(driver);

      Properties props = new Properties();

      props.setProperty(OracleConnection.CONNECTION_PROPERTY_THIN_VSESSION_OSUSER,"oracle");

      Connection conn = DriverManager.getConnection( url, props);

       

      when i run the above code using thin driver, it gives error as "invalid username/password ; logon denied'

      using oci driver error is ::  "no ocijdbc11 in java.library.path" but i am using oracle 10g and in LD_LIBRARAY_PATH libocijdbc10.so is present. but still looking for libocijdbc11.so.

       

       

      Please help me to resolve the issue.

      Thanks

        • 1. Re: Unable to connect to oracle database using os authentication?
          sb92075

          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

               ("jdbc:oracle:thin:@//localhost:1521/v112", "scott", "tiger");

                                  // @//machineName:port/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:~$

          • 2. Re: Unable to connect to oracle database using os authentication?
            Mark D Powell

            Should 5521 be 1521?  What port is your listener listening on?

             

            HTH -- Mark D Powell --

            • 3. Re: Unable to connect to oracle database using os authentication?
              user10839503

              port is correct...it is 5521..

              • 4. Re: Unable to connect to oracle database using os authentication?
                user10839503

                I am using os authentication. The code u have written is for simple JDBC connection to oracle. this any way works.

                I have to connect to db using os authenticated user like oracle. OS authentication does not require any password to connect to db.

                • 5. Re: Unable to connect to oracle database using os authentication?
                  sb92075

                  user10839503 wrote:

                   

                  I am using os authentication. The code u have written is for simple JDBC connection to oracle. this any way works.

                  I have to connect to db using os authenticated user like oracle. OS authentication does not require any password to connect to db.

                  JDBC uses the NETWORK

                  NETWORK connect & OS authentication are mutually exclusive.

                  OS authentication only works when you start  by being physically logged on to the DB Server at the OS level.

                  • 6. Re: Unable to connect to oracle database using os authentication?
                    Mark D Powell

                    When you say OS authenicated user are your referring to an Oracle user created as "create user bob identified externally" and which can then connect to Oracle using "sqlplus /" ?  It is the forward slash that identifies the connection as OS authenicated.  It the OS user matches an Oracle username identified as identified externally the connection is made.  If so, try passing slash as the username in the connection.

                     

                    If you want a sysdba connection then I do not know if the java thin client supports this type of connection.  I suspect you first need a thick connection and then I would also expect that the connection would be made via a network protocol even from the same machine in which case an Oracle password file would be required and I would expect the connection woutld have to pass in a sysdba authorized username with its password.

                     

                    In either case what documentation are you following that tells you what you want to do is possible.  Maybe by looking at it someone can spot the error.

                     

                    HTH -- Mark D Powell --

                    • 7. Re: Unable to connect to oracle database using os authentication?
                      EdStevens

                      user10839503 wrote:

                       

                      I am using os authentication. The code u have written is for simple JDBC connection to oracle. this any way works.

                      I have to connect to db using os authenticated user like oracle. OS authentication does not require any password to connect to db.

                      I have been watching this thread, and am finally compelled to ask why you have a "need" to have a jdbc connection without using a password?  I'm beginning to think the problem itself needs to be re-defined.

                      • 8. Re: Unable to connect to oracle database using os authentication?
                        marksmithusa

                        I'm glad we can 'like' a post now - I no longer have to put '+1' as a especially short reply to a lot of your comments

                        • 9. Re: Unable to connect to oracle database using os authentication?
                          marksmithusa

                          Not that this is likely to stop you, but bear in mind that remote_os_authentication is a deprecated parameter in 11g. This means they're getting rid of it (not sure with what, we still use it here) and that it's something to avoid if you're thinking about future proofing your code.

                          • 10. Re: Unable to connect to oracle database using os authentication?
                            user10839503

                            Now the problem is solved...For os authentication we should use jdbc:oracle:oci:@ url. this url doesnt require any ip, user,pwd. and it woks.

                            but this is for only local connection. only 11g and oci driver can be used.

                             

                            Thanks for all the replies.