4 Replies Latest reply on Mar 26, 2010 10:28 AM by microbe

    Connection problem to mySQL database

      Hi everyone,

       

      Like you all, i'm using JBoss and i'm trying to connect it to a database, which is mySQL.

       

      So I'm using JDBC to set a connection, like I did with a local application, but it doesn't work, even if i've done all requiered configurations.

       

      The problem come from the connection, which is established by this line :

       

               con = DriverManager.getConnection("databaseName", "user", "password");

       

      ==> con is null when i run the portlet

       

      Because I succed in getting a connection with a local app, I think the problem come from the configuration of JBoss because this time, It's J2EE.

       

      So here are exact steps I followed :

       

      - Putting mysql-connector-java-5.1.12-bin.jar in /home/myName/Bureau/jboss-portal-2.7.2/server/default/lib

      - Moving mysql-ds.xml from I don't remember where to /home/myName/Bureau/jboss-portal-2.7.2/server/default/deploy

      - Overwritted mysql-ds.xml with :

       

      <?xml version="1.0" encoding="UTF-8"?

       

      <datasources>
        <local-tx-datasource>
          <jndi-name>MySQLDB</jndi-name>
          <connection-url>jdbc:mysql://localhost/databaseName</connection-url>
          <driver-class>com.mysql.jdbc.Driver</driver-class>
          <user-name>user</user-name>
          <password>password</password>
         
          <min-pool-size>5</min-pool-size>
          <max-pool-size>20</max-pool-size>

       

          <idle-timeout-minutes>5</idle-timeout-minutes>

       

          <exception-sorter-class-name>com.mysql.jdbc.integration.jboss.ExtendedMysqlExceptionSorter</exception-sorter-class-name>
          <valid-connection-checker-class-name>com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker</valid-connection-checker-class-name>

       


        </local-tx-datasource>
      </datasources>

       

      That's all i've done, maybe should I say that I use the plugin JBoss tools in eclipse.

       

      Thank you for your future help.

        • 1. Re: Connection problem to mySQL database
          peterj

          You should be acccessing a database connection via the connection pool manager. Do this instead:

           

          InitialContext ctx = new InitialContext();
          DataSource ds = (DataSource)ctx.lookup("java:MySQLDB");  // Name used in *-ds.xml file
          Connection conn = ds.getConnection();
          • 2. Re: Connection problem to mySQL database

            Thanks for a such response, but it doesn't work yet.

             

            I tryied your solution, and it doesn't work, there is a problem in connection in these two lines :

             

            DataSource ds = (DataSource)ctx.lookup("java:MySQLDB");  // Name used in *-ds.xml file

            Connection con = ds.getConnection();

             

            ds contain "org.jboss.resource.adapter.jdbc.WrapperDataSource@109afb8"

             

            I substitued MySQLDB by the name in the xml (which is MySQLDB =] )

             

            Where the problem may come from, maybe I forgot an important step...

            • 3. Re: Connection problem to mySQL database
              peterj

              If ds contains a WrapperDataSource, then the lookup succeeded, in which case you should be given a connection. Unless your *-ds.xml has incorrect connection information. Please post the exception stack trace.

              • 4. Re: Connection problem to mySQL database

                Here is the principal error :

                 

                15:15:22,548 WARN  [loggerI18N] [com.arjuna.ats.internal.jta.transaction.arjunacore.lastResource.disallow] [com.arjuna.ats.internal.jta.transaction.arjunacore.lastResource.disallow] Adding multiple last resources is disallowed. Current resource is org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@339dd9
                15:15:22,552 ERROR [STDERR] org.jboss.util.NestedSQLException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: 7f000101:e017:4bacc11e:1ec status: ActionStatus.ABORT_ONLY >); - nested throwable: (org.jboss.resource.JBossResourceException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: 7f000101:e017:4bacc11e:1ec status: ActionStatus.ABORT_ONLY >))

                at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:95)