2 Replies Latest reply on Jan 11, 2005 10:32 AM by Weston Price

    creating connection pool! please help me!

    Ramazan Pekin Newbie

      I want to connect to mysql db from the ejb. I have learned that I have to create a connection pool. I have looked but I cant find how it is being. first of all I want to explaing what I have done.

      --------------------------------------------------------------------------------------------------------------------------------------------------------------------------

      Step 1: mysql-ds.xml
      a) Take the mysql-ds.xml file located in the [JBOSS_HOME]/docs/examples/jca folder and place it in the deploy folder.

      I have configured this xml file like this:


      <local-tx-datasource>
      <jndi-name>jspNedirMysql</jndi-name>
      <connection-url>jdbc:mysql://localhost:3306/jspNedir</connection-url>
      <driver-class>com.mysql.jdbc.Driver</driver-class>
      <user-name>root</user-name>

      </local-tx-datasource>



      b) Remove the hsqldb-ds.xml from the deploy folder and save it somewhere else.

      Step 2: ejb-deployer.xml
      Edit this file, which is located in the deploy folder.

      a) Find INTERVAL in the file and change this column name to something else. This is required because INTERVAL is a reserved word for MySQL 4.0. The symptom for not having fixed this is am error mentioning INTERVAL bigint when deploying an EJB.

      b) Find other in the file and change this type to text. This is required because type other does not exist in MySQL 4.0.

      Step 3: standardjaws.xml
      Edit this file, which is located in the conf folder of the server. Change the type-mapping of the datasource from Hypersonic SQL to mySQL Note that these names are case sensitive.

      Step 4: JMS configuration descriptors
      a) Remove hsqldb-jdbc2-service.xml from folder deploy/jms. Save this file somewhere else.

      b) Copy mysql-jdbc2-service.xml from folder docs/example/jms to deploy/jms.

      c) Edit mysql-jdbc2-service.xml and change the datasource name if applicable. In my configuration I don't use HSQL at all so I configured the default datasource DefaultDS for MySQL. In this file, change mySQLDS to DefaultDS. Note that datasource names are case sensitive.

      Step 5: Install MySQL Java Connector
      Download MySQL Connector/J and place the file mysql-connector-java-3.0.15-ga-bin.jar in the lib folder of the server.

      --------------------------------------------------------------------------------------------------------------------------------------------------------------------------


      After all of these how can I connect to mysql from ejb, what I have to do? did I create a connection pool with this? please, please, please help me.

        • 1. Re: creating connection pool! please help me!
          Ramazan Pekin Newbie

          try
          {
          InitialContext ctx = new InitialContext();
          DataSource ds = (DataSource)ctx.lookup("jspNedirMysql");
          java.sql.Connection jspNedirCon = null;
          jspNedirCon = ds.getConnection();
          }catch(SQLException ex)
          {
          setMessage(ex.toString());
          }catch(NamingException ex)
          {
          setMessage(ex.toString());
          }

          ------------------------------------------------------------


          I have tried that and this error have been occured

          javax.naming.NameNotFoundException: jspNedirMysql not bound

          please help me.

          • 2. Re: creating connection pool! please help me!
            Weston Price Newbie

            There are a few things to look for:

            1) Use the JNDIView MBean to list the JNDI context and make sure that DataSource, as you have configured it is showing up. You should see it in the Global JNDI namespace.

            2) Add a resource reference to application component (EJB or otherwise) that allows a logical name mapping to a physical JNDI name. This would show up as something like

            <resource-ref id="ResourceRef_1105457328015">
            <res-ref-name>data</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
            <res-sharing-scope>Shareable</res-sharing-scope>
            </resource-ref>


            Then, you would look up your datasource as
            DataSource ds = (DataSource)ctx.lookup("java:comp/env/data");

            I may be a bit confused on why you are removing or altering the Hypersonic datasource. You should just be able to deploy your MySQL datasource without modifying the default data source at all. Is there something I am missing?

            Weston

            i