4 Replies Latest reply on Jul 4, 2006 8:06 AM by greenday_ra

    using others DBMS in jboss

    greenday_ra

      Hi all.

      i write a program that use mssql server for DB.
      in servlets i can use sql server connection properly.
      but when i try to use sqlserver in EJB, an exception occurs.
      i found that in my ejb, when i get DB connection, it point to Default ds (HSQLDB).
      i think i must make a configuration file that tell jboss that i want to use mssql connection on there. but what and how ?

      i have these configuration files in my program and i also do copy mssql driver in ..\server\default\ and mssql-ds.xml in ..\server\default\deploy\ .

      thanks

      // mssql-xa-ds.xml ===========


      <xa-datasource>
      <jndi-name>myjndi</jndi-name>
      <track-connection-by-tx />
      <isSameRM-override-value>false</isSameRM-override-value>
      <xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerXADataSource</xa-datasource-class>
      <xa-datasource-property name="ServerName">server</xa-datasource-property>
      <xa-datasource-property name="DatabaseName">mydb</xa-datasource-property>
      <xa-datasource-property name="SelectMethod">cursor</xa-datasource-property>
      <user-name>user</user-name>
      ******

      <type-mapping>MS SQLSERVER2000</type-mapping>

      </xa-datasource>


      //web.xml ================

      ...

      <resource-ref>
      <res-ref-name>jdbc/myjndi</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>

      ....

      //jboss-web.xml==============
      ....
      <resource-ref>
      <res-ref-name>jdbc/myjndi</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <jndi-name>java:/myjndi</jndi-name>
      </resource-ref>

      ....

        • 1. Re: using others DBMS in jboss
          wdfink

          What kind of Exception?
          During deploy or when you use it?
          In which EJB do you use the DB-Connection? Session or Entity?

          Wolf

          • 2. Re: using others DBMS in jboss
            greenday_ra

            Thank you fro your reply.

            i got exception in runtime when i try to use my ejb.
            but about ejb. i use BMP. i know that there is a jbosscmp-jdbc file for setting datasource in CMP but how about BMP.
            i try to add these setting in ejb-jar.xml but it was useless... :-(

            ...
            <resource-ref>
            <res-ref-name>jdbc/myjndi</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
            </resource-ref>




            thakns

            • 3. Re: using others DBMS in jboss
              wdfink

              When you use BMP you have to create your own connection like :

              public class MyEntity implements EntityBean {
               private Connection getConnection() {
               Context ctx=new InitialContext();
               DataSource ds=(DataSource)ctx.lookup("java:/myEntityConnection");
               return(ds.getConnection();
               }
              
               pubic void ejbStore() throws EJBException {
               Connection con=null;
               try {
               con=getConnection();
               ... your Code
               }finnaly{
               if(con!=null) {
               con.close();
               }
               }
              }
              


              This code should work, I test it a long time ago ;-)
              I use CMP 2.x, it's easier to implement and the performance is fortunately the same as BMP.

              Wolf

              • 4. Re: using others DBMS in jboss
                greenday_ra

                Yes, its work, :-)

                Thank you so much.

                i have a error in my connection code.

                DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/myjndi");
                changed to
                DataSource ds=(DataSource)ctx.lookup("java:/myjndi");
                
                


                Thank you again.