6 Replies Latest reply on Feb 17, 2003 6:18 PM by Koen Maes

    jboss-3.0.3_tomcat-4.1.12 MSSQL 2000 Connection problem, Ple

    David Newbie

      Hello,

      I keep getting "java.sql.SQLException: No suitable driver" when trying to connect to MSSQL 2000 using MS jdbc driver, I have jboss-3.0.3+Tomcat-4.1.12 bundle, I had the same problem with jboss-3.0.0+Tomcat-4.0.3 bundle. Jboss started up fine and other examples is working fine but I could never get it to talk to MSSQL 2000, I got Tomcat to talk to MSSQL 2000 fine using servlet.

      I looked though all the postings and still could not figure out what I am missing, it seems like it could not find the jar files, but they're all there.

      Please help.

      Below are my setup:

      1) My classpath is pointing to the three jar files:
      /usr/local/msSQLjdbc/lib/msbase.jar:/usr/local/msSQLjdbc/lib/mssqlserver.jar:/usr/local/msSQLjdbc/lib/msutil.ja

      2) the three jar files are also in the /lib directory
      lib/msbase.jar
      lib/mssqlserver.jar
      lib/msutil.jar

      3) my mssql-service.xml is as follow:
      <?xml version="1.0" encoding="UTF-8"?>

      <!-- ===================================================================== -->
      <!-- -->
      <!-- JBoss Server Configuration -->
      <!-- -->
      <!-- ===================================================================== -->



      <!-- ======================================================================-->
      <!-- New ConnectionManager setup for Microsoft SQL Server 2000 driver -->
      <!-- You may download the latest Microsoft JDBC driver from *Microsoft* -->
      <!-- http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/MSDN-FILES/027/001/779
      /msdncompositedoc.xml&frame=true -->
      <!-- Build jmx-api (build/build.sh all) and view for config documentation -->
      <!-- ===================================================================== -->




      <!-- Include a login module configuration named MSSQLDbRealm.
      Update your login-conf.xml, here is an example for a
      ConfiguredIdentityLoginModule:

      <application-policy name = "MSSQLDbRealm">

      <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule" flag = "required">
      <module-option name = "principal">yourprincipal</module-option>
      <module-option name = "userName">yourusername</module-option>
      <module-option name = "password">yourpassword</module-option>
      <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=MSSQLDS</module-opti
      on>
      </login-module>

      </application-policy>

      NOTE: the application-policy name attribute must match SecurityDomainJndiName, and the
      module-option name = "managedConnectionFactoryName"
      must match the object name of the ConnectionManager you are configuring here.
      -->
      <!--comment out this line if you are using the MSSQLDbRealm above-->
      MSSQLDbRealm

      <depends optional-attribute-name="ManagedConnectionFactoryName">
      <!--embedded mbean-->


      MSSQLDS



      <config-property name="ConnectionURL" type="java.lang.String">jdbc:microsoft:sqlserver://hunter:1433;Selec
      tMethod=cursor;DatabaseName=extraitems</config-property>
      <config-property name="DriverClass" type="java.lang.String">com.microsoft.jdbc.sqlserver.SQLServerDriver</
      config-property>
      <!--set these only if you want only default logins, not through JAAS
      <config-property name="UserName" type="java.lang.String">sa</config-property>
      <config-property name="Password" type="java.lang.String"></config-property>-->



      <!--Below here are advanced properties -->
      <!--hack-->
      <depends optional-attribute-name="OldRarDeployment">jboss.jca:service=RARDeployment,name=JBoss LocalTransa
      ction JDBC Wrapper



      <depends optional-attribute-name="ManagedConnectionPool">
      <!--embedded mbean-->


      0
      50
      5000
      15
      <!--criteria indicates if Subject (from security domain) or app supplied
      parameters (such as from getConnection(user, pw)) are used to distinguish
      connections in the pool. Choices are
      ByContainerAndApplication (use both),
      ByContainer (use Subject),
      ByApplication (use app supplied params only),
      ByNothing (all connections are equivalent, usually if adapter supports
      reauthentication)-->
      ByContainer



      <depends optional-attribute-name="CachedConnectionManager">jboss.jca:service=CachedConnectionManager</depe
      nds>

      <depends optional-attribute-name="JaasSecurityManagerService">jboss.security:service=JaasSecurityManager</
      depends>

      java:/TransactionManager
      <!--make the rar deploy! hack till better deployment-->
      jboss.jca:service=RARDeployer





      4) Below are the changes I made in the standardjbosscmp-jdbc.xml

      java:/MSSQLDS
      <datasource-mapping>MS SQLSERVER2000</datasource-mapping>

      5) Below are the changes I made in the standardjaws.xml
      java:/MSSQLDS
      <type-mapping>MS SQLSERVER2000</type-mapping>
      false

      Thank you.

        • 1. Re: jboss-3.0.3_tomcat-4.1.12 MSSQL 2000 Connection problem,
          Sebastien ASTIE Newbie

          Hello,

          I have a question:
          Did you put the 3 jar files under %JBOSS_HOME%/lib or %JBOSS_HOME%/server/default/lib (assuming you run the default configuration)? If you didn't put them in the default configuration li folder, you might want try it.

          I use SQL Server 2000 with the Microsoft JDBC driver, and it works for me...

          I Hope it will work for you.

          Regards,
          Sebastien

          • 2. Re: jboss-3.0.3_tomcat-4.1.12 MSSQL 2000 Connection problem,
            David Newbie

            Thank you for the Reply, yes I have the three jar files in both of the directory you specified and it still does not work. I would be greatly appreciated if you can attached your setup files.

            I was away, therefore I couldn't reply to you sooner.

            Thanks again,

            -David

            • 3. Re: jboss-3.0.3_tomcat-4.1.12 MSSQL 2000 Connection problem,
              David Newbie

              Thanks again for the reply. Yes, I have the three jar files in both places.

              Following is part of my log:

              1:31:41,821 INFO [STDOUT] setEntityContext
              01:31:41,937 INFO [STDOUT] ejbFindByName
              01:31:41,984 INFO [STDOUT] java.sql.SQLException: No suitable driver
              01:31:42,053 ERROR [LogInterceptor] EJBException, causedBy:
              java.lang.NullPointerException
              at com.brainysoftware.ejb.ProductBean.ejbFindByName(ProductBean.java:144)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:324)
              at org.jboss.ejb.plugins.BMPPersistenceManager.callFinderMethod(BMPPersistenceManager.java:638)
              at org.jboss.ejb.plugins.BMPPersistenceManager.findEntities(BMPPersistenceManager.java:340)
              at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.findEntities(CachedConnectionInter
              ceptor.java:323)
              ......................................

              Below is the piece of code that cause the problem, it's in the line "prepareStatement".

              public Enumeration ejbFindByName(String name)
              throws RemoteException, FinderException {
              System.out.println("ejbFindByName");
              Vector products = new Vector();
              Connection con = null;
              PreparedStatement ps = null;
              ResultSet rs = null;

              try {
              String sql = "SELECT ProductId " +
              " FROM ProductTest" +
              " WHERE ProductName=?";
              con = getConnection();
              ps = con.prepareStatement(sql);
              ps.setString(1, name);
              rs = ps.executeQuery();
              ............................
              .................................

              Below is the "getConnection" function:

              public Connection getConnection() {

              String dbUrl = null;
              String userName = null;
              String password = null;
              Context initialContext;
              Context environment;
              Connection connection = null;

              try {
              initialContext = new InitialContext();
              environment = (Context) initialContext.lookup("java:comp/env");
              dbUrl = (String) environment.lookup("dbUrl");
              userName = (String) environment.lookup("dbUserName");
              password = (String) environment.lookup("dbPassword");
              }
              catch (NamingException e) {
              System.out.println(e.toString());
              }
              try {
              connection = DriverManager.getConnection(dbUrl, userName, password);
              }
              catch (SQLException e) {
              System.out.println(e.toString());
              }
              return connection;
              }

              • 4. Re: jboss-3.0.3_tomcat-4.1.12 MSSQL 2000 Connection problem,
                David Jencks Master

                You aren't using the connection pooling/jca framework at all. Please look at the quickstart guide or perhaps one ot the testsuite examples.

                • 5. Re: jboss-3.0.3_tomcat-4.1.12 MSSQL 2000 Connection problem,
                  David Newbie

                  Maybe my terminology are wrong, but the simple matter is that I am having the problem of keep getting "no suitable driver", I think I am using JCA framework but not sure about connection pooling.

                  I did look at the quickstart guide but cannot find any testsuite examples that connect to MSSQL 2000 via JDBC.

                  It would help if you can tell me what I did wrong instead, if I can figure out from the quickstart guide then I wouldn't be posting it on here.

                  Thanks for you reply anyway.

                  • 6. Re: jboss-3.0.3_tomcat-4.1.12 MSSQL 2000 Connection problem,
                    Koen Maes Newbie

                    IMO: this happens when there's a typo in the connection URL ...

                    rgds,
                    koen