10 Replies Latest reply: Jun 10, 2010 3:38 PM by 778643 RSS

    Java 10g OCI connection

      I am not able to connect to oracle 10g from java(j2sdk1.4.2_04) using OCI. I have the basic instantclient10_1 downloaded and I have made my classpath and path point to the instantclient directory. Os used is win2k.

      I think I am able to load the driver because
      Class.forName ("oracle.jdbc.driver.OracleDriver"); given inside try doesn't get caught.

      when I use
      DriverManager.getConnection("jdbc:oracle:oci8:scott/tiger@"); I get runtime error(no compile error)

      Exception in thread "main" java.lang.UnsatisfiedLinkError: t2cGetCharSet
      at oracle.jdbc.driver.T2CConnection.t2cGetCharSet(Native Method)
      at oracle.jdbc.driver.T2CConnection.getCharSetIds(T2CConnection.java:290
      7) and some more lines.

      The same error I get if I use oci instead of oci8 and if I add orcl after @.

      I then tried
      java -classpath %cp% -Djava.library.path=C:\instantclient MyJavaApp
      which gives
      java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

      But I am able to connect using thin client. Please help in setting my oci connection right.
        • 1. Re: Java 10g OCI connection
          They change the class name to oracle.jdbc.OracleDriver. Try that and see if it helps.
          • 2. Re: Java 10g OCI connection
            I've noticed that the instant client works with 10gR1 and not so well with 10gR2.

            Are you using 10.0.2 ? Or 10.2 of Oracle?

            Some links that might help:



            • 3. Re: Java 10g OCI connection
              Also if you are installing on windows you might want to be sure and specify the NLS lang variable when you install the database. Dont pick the default, pick the latin character set, the error message you recieved looks like its a character conversion error.
              • 4. Re: Java 10g OCI connection
                The last thing to check is your tnsnames.ora, sqlnet.ora, and listener.ora

                Since 9i connection is made through a service name and not the sid:

                connect descriptor
                A specially formatted description of the destination for a network connection. A connect descriptor contains destination service and network route information.

                The destination service is indicated by using its service name for Oracle9i or Oracle8i databases or its Oracle System Identifier (SID) for Oracle release 8.0 databases. The network route provides, at a minimum, the location of the listener through use of a network address.

                Here are the basics on using the tools to set that up


                Some good info on the listener:


                Some nifty advanced tuning stuff:
                • 5. Re: Java 10g OCI connection
                  As far as the NLS lang variable goes - typically if you are speaking english or some other european latin based derivative, the latin charcter set will work well with what you have installed as the NLS Lang Variable in Oracle... thats the short answer. Here is the long answer:


                  4 important remarks:

                  * Setting the NLS_LANG to the characterset of the database MAY be correct
                  but IS NOT ALWAYS correct. Please DO NOT assume that NLS_LANG needs to be ALWAYS the same as the database characterset. THIS IS NOT TRUE.

                  * The characterset defined with the NLS_LANG parameter does NOT CHANGE
                  your client's characterset, it is used to let Oracle know what characterset
                  you are USING on the client side, so Oracle can do the proper conversion.
                  • 6. Re: Java 10g OCI connection
                    I just realized after the last post, that not everyone is amiliar with the latin character set.

                    I'm refering to ISO 8859-1 Or WE8ISO8859P1

                    The default on my pc is
                    [AMERICAN_AMERICA.WE8MSWIN1252] which may or may not be what I need.

                    But some how for me the following always does the trick nicely.


                    The reall killer in going from UTF to another format or vice versa. The 10g OCI client puts to much faith in Microsoft and defaults you to whatever is in windows.

                    -- Checking your NLS:

                    From windows, to check the NLS_LANG, you need to open a command prompt and to run sqlplus in command line mode.

                    First, check if it's set in the environment:

                    SQL> host echo %NLS_LANG%

                    If this reports just %NLS_LANG% back, the variable is not set in the
                    environment. If it's set it reports something like
                    ENGLISH_UNITED KINGDOM.WE8PC850

                    If NLS_LANG is not set in the enviroment, you should check the value
                    in the registry:

                    SQL> @.[%NLS_LANG%].

                    If you get something like:
                    unable to open file ".[ENGLISH_UNITED KINGDOM.WE8ISO8859P1]."
                    the "file name" between the '[]' is the value of the registry parameter.

                    (This is NOT an error but just a "trick" to get the NLS_LANG value)

                    If you get this as result:
                    unable to open file ".[%NLS_LANG%]."
                    then the parameter NLS_LANG is also not set in the registry.

                    Note: the @.[%NLS_LANG%]. "trick" reports the NLS_LANG known by the sqlplus
                    executable, it will not read the registry itself.
                    But then you are not sure if the variable is set in the enviroment or in the
                    registry. That's the reason of checking with the host commando first.
                    • 7. Re: Java 10g OCI connection
                      One last gem that might help just incase you get a link error:

                      java.lang.UnsatisfiedLinkError: t2cCreateState

                      java -classpath %cp% -Djava.library.path=C:\instantclient10_1 MyJavaApp

                      And a sample tnsnames.ora file entry for you:
                      -- C:\instantclient10_1\tnsnames.ora
                      MYDB = (DESCRIPTION=
                           ( ADDRESS= (PROTOCOL=tcp)(HOST=MYHOST)(PORT=1521) )
                           ( CONNECT_DATA=(SERVICE_NAME=ORCL) )

                      Sample connection jdbc url

                      It all works nicely for me. Going live with my first Oracle 10g RAC in production on Sunday. Wish me luck! OCI works fantastically well with the intant client, tomcat and a 10G RAC. TAF and load balancing work nicely with OCI.
                      • 8. Re: Java 10g OCI connection
                        In my case it was wrong ojdbc14_g.jar comming from Oracle XE Database.

                        I replaced it with the same file coming from the database I'm connecting to and it works !
                        • 9. Re: Java 10g OCI connection
                          Interesting note on the ojdbc14_g.jar. I've verified you can get the same error if you have the wrong JDBC driver for your application. Find the ojdbc*.jar file in your application and replace it with the latest driver from here:

                          Edited by: Britton LaRoche on Jun 9, 2009 6:34 PM
                          • 10. Re: Java 10g OCI connection
                            user9522939 wrote:
                            In my case it was wrong ojdbc14_g.jar comming from Oracle XE Database.

                            I replaced it with the same file coming from the database I'm connecting to and it works !
                            That worked for me as well. Thanks.