JBoss Community

Re: Can't connect to MySQL in Java EE/JBoss application

created by Sz Krze in Datasource Configuration - View the full discussion

All right, I've repeated all the steps from the beginning as a fresh morning man and it worked. Still don't know why, but here're a few things that might've solved the problem:

 

 

 

Here're the steps I've followed (I've just replicated them to be sure they're still not working):

  1. Downloaded mysql-connector-java-5.0.8-bin.jar from http://www.mysql.com/downloads/connector/j/5.0.html#downloads
  2. Placed it in jboss-6.0.0.Final\server\default\lib
  3. Created a new Connection Profile in Eclipse using Data Source Explorer (I don't know if that step is even necessary). In the wizard I've also created a new Driver Definition using the 5.0.8 connector. The ping succeeded and my database is visible from within the Data Source Explorer.
  4. Generated -ds.xml file from the CP mentioned in 3) using File->New->Other...->JBoss Tools Web->JBoss Datasource (-ds.xml) (using AS5 format) and placed it in jboss-6.0.0.Final\server\default\deploy\Mysql_local-ds.xml as well as project's META-INF\Mysql_local-ds.xml (corrected: when I placed it in both places simultaneously, I received ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] Error installing to Real: (...) Caused by: java.lang.IllegalStateException: jboss.jca:name=MP01Datasource2,service=ManagedConnectionFactory is already installed.
  5. I've added the db's jar to build path usign [rmb on project]->Build Path->Configure Build Path...->Add Library->Connectivity Driver Definition and chose the one I've defined in 3)

 

I have also deleted some old .jar deployments from my other test projects that got stuck in the workspace\.metadata\.plugins\org.jboss.ide.eclipse.as.core\JBoss_6.x_Runtime_Server1345902635716\deploy folder (supposedly due to incorrect shutdown), but I sincerely doubt that was what helped.

 

I suppose the main cause might've been that as I was swapping the drivers and Driver Definitions (I've been moving from 5.1.sth to 5.0.8) I forgot to swap them in the pj's build path as well and involuntarily left the old one.

 

My current persistence.xml

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

<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"

       version="2.0">

  <persistence-unit name="mp" transaction-type="JTA">

    <jta-data-source>java:/MP01Datasource2</jta-data-source>

           <properties>

       <!--s

       <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>

       -->

       <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>

       <property name="hibernate.hbm2ddl.auto" value="create-drop"/>

   </properties>

  </persistence-unit>

</persistence>

 

Mysql_local-ds.xml

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

<!DOCTYPE datasources

    PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"

    "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">

<datasources>

  

   <local-tx-datasource>

      <jndi-name>MP01Datasource2</jndi-name>

      <use-java-context>true</use-java-context>

      <connection-url>jdbc:mysql://localhost:3306/mp</connection-url>

      <driver-class>com.mysql.jdbc.Driver</driver-class>

      <user-name>x</user-name>

      <password>y</password>

   </local-tx-datasource>

   

</datasources>



Reply to this message by going to Community

Start a new discussion in Datasource Configuration at Community