4 Replies Latest reply on Apr 6, 2013 5:35 PM by rahulkaushik84

    java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@......

    thomas2008ch

      Hi,

       

      I have the foloinwg code:

      [code]

      public class CounterBean implements Counter {

          String name = "java:jboss/exported/CounterBean";

          String value = "JNDIExample instantiated at " + new Date().toString();

          private static final String ICFP_USER = "test";

          private static final String ICFP_PWD = "test";

          private static final String ICFP_URL = "jdbc:oracle:thin:@mydb:1521:jbona1";

       

              public String printCount(int countNumber) {

              ConnectOracleServer connServer = new ConnectOracleServer();

       

              try {

                  new javax.naming.InitialContext().rebind(name, value);

                 

                  connServer.dbConnect(ICFP_URL, ICFP_USER, ICFP_PWD);

                 

              } catch (NamingException e1) {

                  // TODO Auto-generated catch block

                  e1.printStackTrace();

              }

             

              System.out.println("Request from Client " + countNumber);

              String rt = new Integer(countNumber).toString();

              return "Response from server " + rt;

          }

      }

       

      [/code]

       

      and

       

      [code]

      public class ConnectOracleServer {

          public void dbConnect(String db_connect_string, String db_userid,

                  String db_password) {

              try {

                  Connection conn = DriverManager.getConnection(db_connect_string,

                          db_userid, db_password);

              } catch (SQLException e) {

                  // TODO Auto-generated catch block

                  e.printStackTrace();

              }

       

          }

      }

       

      [/code]

       

       

      My codes run well in Jboss AS 5 and 6. But not in Jboss AS 7. I got exception like:

       

      ...

      14:29:40,375 ERROR [stderr] (EJB default - 1) java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@raca2-vip:1521:jbona1

      14:29:40,376 ERROR [stderr] (EJB default - 1)   at java.sql.DriverManager.getConnection(DriverManager.java:602)

      14:29:40,376 ERROR [stderr] (EJB default - 1)   at java.sql.DriverManager.getConnection(DriverManager.java:185)

      14:29:40,377 ERROR [stderr] (EJB default - 1)   at com.my.app.ConnectOracleServer.dbConnect(ConnectOracleServer.java:11)

      14:29:40,377 ERROR [stderr] (EJB default - 1)   at com.my.app.CounterBean.printCount(CounterBean.java:25)

      14:29:40,377 ERROR [stderr] (EJB default - 1)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      14:29:40,377 ERROR [stderr] (EJB default - 1)   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

      14:29:40,377 ERROR [stderr] (EJB default - 1)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

      14:29:40,378 ERROR [stderr] (EJB default - 1)   at java.lang.reflect.Method.invoke(Method.java:597)

      14:29:40,378 ERROR [stderr] (EJB default - 1)   at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72)

      14:29:40,378 ERROR [stderr] (EJB default - 1)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

      14:29:40,378 ERROR [stderr] (EJB default - 1)   at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)

      14:29:40,379 ERROR [stderr] (EJB default - 1)   at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:36)

      14:29:40,379 ERROR [stderr] (EJB default - 1)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

      14:29:40,379 ERROR [stderr] (EJB default - 1)   at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43)

      14:29:40,381 ERROR [stderr] (EJB default - 1)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

      14:29:40,387 ERROR [stderr] (EJB default - 1)   at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)

      14:29:40,388 ERROR [stderr] (EJB default - 1)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

      14:29:40,388 ERROR [stderr] (EJB default - 1)   at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)

      14:29:40,391 ERROR [stderr] (EJB default - 1)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

      14:29:40,391 ERROR [stderr] (EJB default - 1)   at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)

      14:29:40,391 ERROR [stderr] (EJB default - 1)   at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53)

      14:29:40,391 ERROR [stderr] (EJB default - 1)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

      14:29:40,392 ERROR [stderr] (EJB default - 1)   at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51)

      14:29:40,392 ERROR [stderr] (EJB default - 1)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

      14:29:40,392 ERROR [stderr] (EJB default - 1)   at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:227)

      14:29:40,392 ERROR [stderr] (EJB default - 1)   at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:303)

      14:29:40,392 ERROR [stderr] (EJB default - 1)   at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:189)

      14:29:40,392 ERROR [stderr] (EJB default - 1)   at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)

      14:29:40,393 ERROR [stderr] (EJB default - 1)   at org.jboss.as.ejb3.remote.EJBRemoteTransactionPropagatingInterceptor.processInvocation(EJBRemoteTransactionPropagatingInterceptor.java:80)

      ...

       

       

      The Oracle driver ojdbc6-11.2.0.2.0.jar is saved under $JBOSS_HOME/standalone/lib/ext

        • 1. Re: java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@......
          cfang

          The classloading and dependency resolution are different in as7.  Have you tried installing the driver jar as a dependency module, under jboss.home/modules? 

          https://community.jboss.org/wiki/DataSourceConfigurationInAS7

          • 2. Re: java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@......
            jaysensharma

            Hi,

             

              As you are Not using "DataSource" rather your code is trying to establish connection to the Database using DriverManager  like following:

             

             

            Connection conn = DriverManager.getConnection(db_connect_string,   db_userid, db_password);

             

            So change the above code like following in order to load the JDBC Driver class explicitly as following:

             

            Class.forName("oracle.jdbc.OracleDriver");                    //      Add this line to   Load the Oracle Driver first  

             

            Connection conn = DriverManager.getConnection(db_connect_string,   db_userid, db_password);

             

             

              So you should either  place the " ojdbc6-11.2.0.2.0.jar" insdie you application "WEB-INF/lib"  and then add the [Class.forName("oracle.jdbc.OracleDriver"); ]  statement in your code (ConnectOracleServer.java)  before creating connection using DriverManager.

             

              If you donot want to place the JDBC Driver inside your Application then create a Oracle Jdbc Driver module and then add make it available to your application using "jboss-depoyment-structure.xml" file   [NOTE:  still you will need to load the class explicitly inside your code (ConnectOracleServer.java) as  Class.forName("oracle.jdbc.OracleDriver");   ]

             

              If you are using EJB Jar then in that case you can add "META-INF/jboss-deployment-structure.xml"    point to your Oracle JDBC Module   or  you can add a dependency to your Module using "$EJB_JAR/META-INF/MANIFEST.MF" file  by adding the "Dependencies"   attribute.

            • 3. Re: java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@......
              marcelomrwin

              Works for meu Jay, thanks. One more question. I was trying connect to a database using spring datasource. The spring libraries was configured as modules in jboss as 7. oracle driver too. So, I'm aways facing the problem java.sql.SQLException: No suitable driver found for... Removing connection from spring dependencies and load as you say the code works ok. Why when I try to use connection from spring this error occurs?

              • 4. Re: java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@......
                rahulkaushik84

                install driver as a module in jboss 7 ...it should work.