0 Replies Latest reply on Aug 27, 2014 1:38 PM by davidj

    Why does the MySQL JDBC driver behave strangely when setting-up a datasource

    davidj

      Hi,

      I'm using JBoss 6.3 and 6.2 EAP.  I can successfully setup JDBC drivers without problems using any of the available methods:

      1) CLI

      2) Deploy the jar file as you would a war file and JBoss magically detects it is a JDBC driver

      3) Create a folder structure in the "modules" folder.

       

      However, the exception is for MySql.  It does not work like the others.  I finally got it to work (as explained below) but I want to understand why it has to work this way.

       

      Let me quickly review how a "normal" JDBC driver is suppose to act in JBoss using CLI:

      Suppose I want to install the JTDS driver for SqlServer 2008 and create a datasource for it using CLI.  The steps I would do are as follows:

      1) Deploy the JAR file by issuing the following command:    deploy jtds-1.3.1.jar --name=JTDS-1.3.1  (assuming you've got the jar file in the "bin" folder wherever you installed JBoss)

      2) Create the datasource by issuing the following command:   data-source add --name=FinanceDatasource --jndi-name=java:/datasources/FinanceDatasource --driver-name=JTDS-1.3.1 --connection-url=jdbc:jtds:sqlserver://FINANCESQL10/FIN_DEV --user-name=foo --password=bar


      Everything is fine.

       

      Now let's to the same thing for MySQL:

       

      1) Deploy the JAR file:    deploy mysql-connector-java-5.1.32-bin.jar --name=mysql-connector-java-5.1.32-bin

      2) Create the datasource:   data-source add --name=EmployeeDatasource --jndi-name=java:/datasources/EmployeeDatasource --driver-name=mysql-connector-java-5.1.32-bin --connection-url=jdbc:mysql://VAR_MYSQL03:3306/EMP_DEV --user-name=foo --password=bar


      This does not work. In-fact the error message is strange, the error message is:

      JBAS014771: Services with missing/unavailable dependencies" => ["jboss.driver-demander.java:/datasources/EmployeeDatasource is missing [jboss.jdbc-driver.mysql-connector-java-5_1_32-bin_jar]


      Notice how the error message refers to a "mysql-connector-java-5_1_32-bin_jar", note how it is looking for "5_1_32" instead of "5.1.32"... strange.


      The solution is to do the following:

      1) Deploy without name:    deploy mysql-connector-java-5.1.32-bin.jar

      2) Create the datasource like this:   data-source add --name=EmployeeDatasource --jndi-name=java:/datasources/EmployeeDatasource --driver-name=mysql-connector-java-5.1.32-bin.jarcom.mysql.jdbc.Driver_5_1 --connection-url=jdbc:mysql://VAR_MYSQL03:3306/EMP_DEV --user-name=foo --password=bar


      Notice the driver-name comes out of nowhere? ... it is almost like the jar file contains two or more drivers and you somehow have to know which one to use.


      Can someone explain this?


      Thanks,


      David