12 Replies Latest reply: Nov 16, 2012 7:35 AM by 974649 Branched to a new discussion. RSS

    Connecting to Oracle using JDBC problem

    498110
      When trying to connect using the following few lines:
                String urn = "jdbc:oracle:thin:@localhost:1521:XE";
                Class.forName("oracle.jdbc.driver.OracleDriver");
                Connection _con = DriverManager.getConnection(urn, "user", "pass");

      I get an ArrayIndexOutOfBounds Exception
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
           at oracle.security.o3logon.C1.r(C1)
           at oracle.security.o3logon.C1.l(C1)
           at oracle.security.o3logon.C0.e(C0)
           at oracle.security.o3logon.O3LoginClientHelper.getEPasswd(O3LoginClientHelper)
           at oracle.jdbc.ttc7.O3log.<init>(O3log.java:287)
           at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:227)
           at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:198)
           at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:251)
           at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:224)
           at java.sql.DriverManager.getConnection(Unknown Source)
           at java.sql.DriverManager.getConnection(Unknown Source)

      I am using JDK 1.4, and I installed the Oracle Database 10g Express Edition.
      If anyone has used JDBC before, and knows how this should be done...
      thanks
        • 1. Re: Connecting to Oracle using JDBC problem
          529993
          I got the same problem, and I got that solved by using the correct jdbc. It should solved your problem by downloading the classes.12.jar from oracle under Oracle Database 10g Release 2 (10.2.0.1.0) JDBC Drivers
          • 2. Re: Connecting to Oracle using JDBC problem
            Ashok Shivarudraiah
            You are using Jdbc version 9.x. Use 10.x to connect to XE and use ojdbc14.jar while using JDK 1.4 instead of classes12.jar. classes12.jar is typically used with JDK 1.2 & JDK 1.3.

            ==
            Ashok
            • 3. Re: Connecting to Oracle using JDBC problem
              392544
              What does the "XE" mean in the statement String urn = "jdbc:oracle:thin:@localhost:1521:XE"; ?
              • 4. Re: Connecting to Oracle using JDBC problem
                Avi Abrami
                Andy,
                XE stands for eXpress Edition.

                Good Luck,
                Avi.
                • 5. Re: Connecting to Oracle using JDBC problem
                  Marius2
                  I'm also having problems with JDBC and java, hoping that some one can help me.

                  Using Red Hat Enterprise and Oracle 10.2

                  import java.io.*;
                  import java.sql.*;

                  public class OraThin
                  {
                  public static void main(String[] args)
                  {
                  try
                  {
                  Connection con = null;
                  Class.forName("oracle.jdbc.driver.OracleDriver");
                  con = DriverManager.getConnection("jdbc:oracle:thin:@orcl","marius","password");
                  Statement s = con.createStatement();
                  s.execute(" INSERT INTO test VALUES(237)");
                  s.close();
                  con.close();
                  }catch(Exception e){e.printStackTrace();}
                  }
                  }


                  CLASSPAT=/u01/app/oracle/product/10.1.0/db_1/jdbc/lib/classes12.zip or
                  CLASSPATH=/u01/app/oracle/product/10.1.0/db_1/jdbc/lib/classes12.jar
                  With these class paths I get the following errors

                  Exception in thread "main" java.lang.AbstractMethodError
                  at JvMakeVTable(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
                  at JvPrepareClass(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
                  at JvWaitForState(java.lang.Class, int) (/usr/lib/libgcj.so.5.0.0)
                  at java.lang.VMClassLoader.linkClass0(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
                  at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
                  at java.lang.Class.initializeClass() (/usr/lib/libgcj.so.5.0.0)
                  at oracle.jdbc.driver.T4CDriverExtension.getConnection(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.util.Properties) (Unknown Source)
                  at oracle.jdbc.driver.OracleDriver.connect(java.lang.String, java.util.Properties) (Unknown Source)
                  at java.sql.DriverManager.getConnection(java.lang.String, java.util.Properties) (/usr/lib/libgcj.so.5.0.0)
                  at java.sql.DriverManager.getConnection(java.lang.String, java.lang.String, java.lang.String) (/usr/lib/libgcj.so.5.0.0)
                  at OraThin.main(java.lang.String[]) (Unknown Source)

                  CLASSPATH=/u01/app/oracle/product/10.1.0/db_1/jdbc/lib/ojdbc14.jar

                  With this class paths I get the following errors:

                  Exception in thread "main" java.lang.NoClassDefFoundError: while resolving class: oracle.jdbc.driver.OracleDriver
                  at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
                  at java.lang.Class.initializeClass() (/usr/lib/libgcj.so.5.0.0)
                  at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0)
                  at java.lang.Class.forName(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
                  at OraThin.main(java.lang.String[]) (Unknown Source)
                  Caused by: java.lang.ClassNotFoundException: oracle.security.pki.OracleWallet not found in [file:/u01/app/oracle/product/10.1.0/db_1/jdbc/lib/ojdbc14.jar, file:/usr/share/java/libgcj-3.4.4.jar, file:./, core:/]
                  at java.net.URLClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
                  at gnu.gcj.runtime.VMClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
                  at java.lang.ClassLoader.loadClass(java.lang.String, boolean) (/usr/lib/libgcj.so.5.0.0)
                  at JvFindClass(_Jv_Utf8Const, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0)
                  at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0)
                  at JvBytecodeVerifier.verify_instructions_0() (/usr/lib/libgcj.so.5.0.0)
                  at JvVerifyMethod(_Jv_InterpMethod) (/usr/lib/libgcj.so.5.0.0)
                  at JvPrepareClass(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
                  at JvWaitForState(java.lang.Class, int) (/usr/lib/libgcj.so.5.0.0)
                  at java.lang.VMClassLoader.linkClass0(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
                  at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
                  ...4 more


                  Any suggestion what I'm doing wrong?

                  Message was edited by:
                  Marius
                  • 6. Re: Connecting to Oracle using JDBC problem
                    Avi Abrami
                    Marius,
                    You asked:
                    Any suggestion what I'm doing wrong?
                    First, your database connection URL looks incorrect.
                    Please check the JDBC Developer's Guide and Reference for details on the correct syntax.

                    Next, I see you are using "gcj" as your java compiler.
                    I remember having problems with that compiler.
                    I suggest you use "javac" that comes with SUN's JDK.

                    Please see this announcement:

                    http://forums.oracle.com/forums/ann.jspa?annID=201

                    Class "oracle.jdbc.driver.OracleDriver" is deprecated in "ojdbc14.jar".

                    Good Luck,
                    Avi.
                    • 7. Re: Connecting to Oracle using JDBC problem
                      Marius2
                      I'm still having trouble after doing what you said. From the manual I figured I need JDK 1.4 so I installed: j2sdk-1.4.1_07-fcs. I have both ojdbc14.jar and orai18n.jar in CLASSPATH.

                      Then I try to compile and run some of the excample I downloaded in the demo.tar fil. The ones I have tried all end in:
                      Exception in thread "main" java.lang.NoClassDefFoundError: JdbcCheckup

                      Can anyone help me solve this problem?
                      • 8. Re: Connecting to Oracle using JDBC problem
                        Kmensah-Oracle
                        Where is JdbcCheckup.class located? This location should be in your classpath.

                        Fwiw, I have working JDBC examples and valid URs, in my book.

                        Kuassi
                        - blog http://db360.blogspot.com/
                        - book http://db360.blogspot.com/2006/08/oracle-database-programming-using-java_01.html
                        • 9. Urgent: Connecting to Oracle using JDBC problem
                          832005
                          Hello,

                          We have an SAJ applicatoion (J2E). We have imlemented junit tests. When we execute test cases, we have the following error. It becom urgent, Please help.

                          java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 7
                               at oracle.security.o3logon.C0.r(C0)
                               at oracle.security.o3logon.C0.l(C0)
                               at oracle.security.o3logon.C1.c(C1)
                               at oracle.security.o3logon.O3LoginClientHelper.getEPasswd(O3LoginClientHelper)
                               at oracle.jdbc.ttc7.O3log.<init>(O3log.java:289)
                               at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:251)
                               at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:249)
                               at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:365)
                               at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:260)
                               at java.sql.DriverManager.getConnection(DriverManager.java:572)
                               at java.sql.DriverManager.getConnection(DriverManager.java:196)
                               at fr.improve.foundations.component.jdbc.impl.JdbcConnectionFactory.createFromDriver(JdbcConnectionFactory.java:254)
                               at fr.improve.foundations.component.jdbc.impl.JdbcConnectionFactory.create(JdbcConnectionFactory.java:126)
                               at fr.improve.foundations.core.connection.ConnectionContext.createConnection(ConnectionContext.java:83)
                               at fr.improve.foundations.core.connection.ConnectionContext.getConnection(ConnectionContext.java:70)
                               at renault.fgs.enterprise.service.util.ConnectionUtils.execute(ConnectionUtils.java:30)
                               at renault.fgs.enterprise.service.impl.FGSearchEnterpriseServiceImpl.fgFieldList(FGSearchEnterpriseServiceImpl.java:164)
                               at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                               at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
                               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                               at java.lang.reflect.Method.invoke(Method.java:618)
                               at fr.improve.foundations.core.layer.ServiceInvocationHandler.forward(ServiceInvocationHandler.java:35)
                               at fr.improve.foundations.core.layer.LayerPipeline$LayerValveContextImpl.forward(LayerPipeline.java:74)
                               at fr.improve.foundations.core.layer.LayerPipeline.process(LayerPipeline.java:52)
                               at fr.improve.foundations.core.layer.ServiceInvocationHandler.invoke(ServiceInvocationHandler.java:30)
                               at $Proxy12.fgFieldList(Unknown Source)
                               at renault.fgs.application.SearchFGApplicationTest.testInit(SearchFGApplicationTest.java:25)
                               at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                               at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
                               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                               at java.lang.reflect.Method.invoke(Method.java:618)
                               at junit.framework.TestCase.runTest(TestCase.java:164)
                               at junit.framework.TestCase.runBare(TestCase.java:130)
                               at junit.framework.TestResult$1.protect(TestResult.java:106)
                               at junit.framework.TestResult.runProtected(TestResult.java:124)
                               at junit.framework.TestResult.run(TestResult.java:109)
                               at junit.framework.TestCase.run(TestCase.java:120)
                               at junit.framework.TestSuite.runTest(TestSuite.java:230)
                               at junit.framework.TestSuite.run(TestSuite.java:225)
                               at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
                               at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
                               at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
                               at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
                               at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
                               at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
                          • 10. Re: Connecting to Oracle using JDBC problem
                            user59706
                            Hi All,

                            Even im facing similar issues, please advise and help. Details as below,

                            System and java spec used:

                            Windows Edition : Windows Server 2008 R2 Standard
                            System type : 64-bit Operating System
                            NetBeansIDE version : 6.1
                            JDK Version : 1.6
                            DB : Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

                            Connection string: : <root>
                            <title>Oracle R12 Prod</title>
                            <jdbc-connection-string>jdbc:oracle:thin:<username>/<password>@<host>:<port>:<SID></jdbc-connection-string>
                            </root>



                            StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
                            java.lang.ArrayIndexOutOfBoundsException: 7
                            at oracle.security.o3logon.C1.r(C1)
                            at oracle.security.o3logon.C1.l(C1)
                            at oracle.security.o3logon.C0.c(C0)
                            at oracle.security.o3logon.O3LoginClientHelper.getEPasswd(O3LoginClientHelper)
                            at oracle.jdbc.ttc7.O3log.<init>(O3log.java:290)
                            at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:251)
                            at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:252)
                            at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:365)
                            at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:260)
                            at java.sql.DriverManager.getConnection(DriverManager.java:582)
                            at java.sql.DriverManager.getConnection(DriverManager.java:207)
                            at db.dbConnect.makeConnection(dbConnect.java:55)
                            at org.apache.jsp.rep.rep1_005fgo_jsp._jspService(rep1_005fgo_jsp.java from :222)
                            at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:93)
                            at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
                            at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
                            at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:470)
                            at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:364)
                            at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
                            at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
                            at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:855)
                            at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:703)
                            at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:660)
                            at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:578)
                            at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:997)
                            at org.apache.jsp.rep.rep1_005fgo0_jsp._jspService(rep1_005fgo0_jsp.java from :111)
                            at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:93)
                            at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
                            at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
                            at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:470)
                            at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:364)
                            at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
                            at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
                            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:290)
                            at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
                            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
                            at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
                            at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
                            at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
                            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
                            at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
                            at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
                            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
                            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
                            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
                            at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
                            at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
                            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
                            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
                            at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
                            at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
                            at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
                            at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
                            at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
                            at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
                            at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
                            at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
                            at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
                            • 11. Re: Connecting to Oracle using JDBC problem
                              944228
                              XE is database name
                              • 12. Re: Connecting to Oracle using JDBC problem
                                974649
                                Hello, I have this problem:

                                Exception in thread "main" java.lang.NullPointerException
                                     at java.lang.String.<init>(String.java:194)
                                     at oracle.sql.CharacterSet.AL32UTF8ToString(CharacterSet.java:1517)
                                     at oracle.jdbc.driver.DBConversion.CharBytesToString(DBConversion.java:589)
                                     at oracle.jdbc.driver.DBConversion.CharBytesToString(DBConversion.java:542)
                                     at oracle.jdbc.driver.T4CTTIoauthenticate.receiveOauth(T4CTTIoauthenticate.java:822)
                                     at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:362)
                                     at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:439)
                                     at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
                                     at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
                                     at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
                                     at java.sql.DriverManager.getConnection(DriverManager.java:579)
                                     at java.sql.DriverManager.getConnection(DriverManager.java:221)
                                     at cr.ac.una.info.p3.accesodatos.Conexion.conectarme(Conexion.java:26)
                                     at cr.ac.una.info.p3.accesodatos.ADAutor.insertar(ADAutor.java:29)
                                     at Principal.Principal.main(Principal.java:23)
                                Java Result: 1

                                My spefication:
                                Oracle Database Express Edition 11g Release 2 (from http://www.oracle.com/technetwork/products/express-edition/downloads/index.html)

                                Windows Home Basic 32 bit
                                JDK 1.7
                                ojdbc14.jar

                                Im using this sintax for my connection:

                                DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
                                conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","aux","root");

                                The exception by wrong URL/User is not throwed.

                                ---------------------------------------------------------------------------------------------------------------------------------------------------
                                UPDATE!!!!!!!: problem solved, was a older version of ojdbc14.jar provided by my university teacher at lab.

                                Thanks to all!!!

                                Edited by: 971646 on 16-nov-2012 5:32