3 Replies Latest reply on Apr 25, 2002 9:26 PM by davidjencks

    how to get a jdbc connection in the session bean

    cs710

      Hi, I started to play around with JBoss 3 days ago. I am very happy with what I have seen so far. However I have a few questions:
      1. How to get a jdbc connection in the session bean?
      2. It seems the default jboss.jcml use XADataSource. Does that mean it uses distributed transaction stuff and do 2 phase commit? If I know I am only using Oracle, is it better to use DataSource (is there a DataSource mbean anyway?)
      3. Does anyone own the documentation for sale? Are they useful? Is it worth owning them?
      4. Can someone recommend a GUI that I can use to create ejb-jar.xml and other config files? It seems manually editting is very tedious and error prone?

      Thanks a lot.

      sc

        • 1. Re: how to get a jdbc connection in the session bean
          lasterra

          protected Connection getConnection()
          {
          String mensajeLog =
          "Cogiendo conexion en " + this.getClass ().getName ();
          if (log.isDebugEnabled ()) log.debug (mensajeLog);

          try {
          InitialContext context = new InitialContext ();
          DataSource source = (DataSource)context.lookup ("java:/MK");
          return source.getConnection ();
          }catch(javax.naming.NamingException ne)
          {
          throw new javax.ejb.EJBException(mensajeLog,ne);
          }catch (java.sql.SQLException sqle)
          {
          throw new javax.ejb.EJBException(mensajeLog,sqle);
          }

          where MK is my connection pool.

          If you don't like edit the deploy jars, use xdoclet and left it generates this files for you.

          Regrasds, enrique.

          • 2. Re: how to get a jdbc connection in the session bean
            cs710

            Thanks. It works.

            • 3. Re: how to get a jdbc connection in the session bean
              davidjencks

              2. Use the XDataSourceLoader (in 2.4.x). Otherwise there is no way for the transaction manager to control the transactions for you. Most dbs don't have working xa drivers, so there is the XADataSourceImpl which makes non xa look like xa (but without actually doing 2pc).

              If you are using db + transacted jms, you want real xa, such as Firebird and expensive db's have.

              3. I only work on 3.0 and still think the $$2.4 docs are worth it. You might find it at your bookstore, too, and take a look.

              4. I recommend xdoclet also.