简体   繁体   中英

JBoss: can not connect to MySQL database

I am running JBoss as standalone version. I would like to connect to my local mysql database

I copied the mysql connector in modules folder

me@air~/Downloads/jboss/standalone/configuration - 10:56:18  $ ls ../../modules/org/mysql/main/
mysql-connector-java-5.1.22-bin.jar

Next I changed the standalone.xml in jboss/standalone/configuration as

                <drivers>
                    <driver name="com.mysql" module="org.mysql" />
                    <driver name="h2" module="com.h2database.h2"> <!-- default provided-->
                        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                    </driver>
                </drivers>

Then I added the datasource as

              <datasource jndi-name="java:/bb" pool-name="bb-pool" enabled="true" use-java-context="true" use-ccm="true">
                    <connection-url>jdbc:mysql://127.0.0.1:3306/mydb</connection-url>
                    <driver>mysql</driver>
                    <pool>
                        <min-pool-size>10</min-pool-size>
                        <max-pool-size>100</max-pool-size>
                        <prefill>true</prefill>
                    </pool>
                    <security>
                        <user-name>bb</user-name>
                        <password>bb</password>
                    </security>
                    <statement>
                        <prepared-statement-cache-size>100</prepared-statement-cache-size>
                        <share-prepared-statements>true</share-prepared-statements>
                    </statement>
                </datasource>

I am using JBoss AS 7.1 . When I start the server on console, I see errors

10:54:47,458 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
10:54:47,671 INFO  [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report
JBAS014775:    New missing/unsatisfied dependencies:
      service jboss.jdbc-driver.mysql (missing) dependents: [service jboss.data-source.java:/bb] 

10:54:47,676 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
10:54:47,676 ERROR [org.jboss.as] (Controller Boot Thread) JBAS015875: JBoss AS 7.1.1.Final "Brontes" started (with errors) in 2000ms - Started 134 of 212 services (2 services failed or missing dependencies, 74 services are passive or on-demand)

and when I hit Ctrl+C , I see

^C10:54:54,998 INFO  [org.jboss.as.osgi] (MSC service thread 1-8) JBAS011942: Stopping OSGi Framework
10:54:55,004 INFO  [org.jboss.as.logging] JBAS011503: Restored bootstrap log handlers
10:54:55,007 INFO  [com.arjuna.ats.jbossatx] ARJUNA032018: Destroying TransactionManagerService
10:54:55,008 INFO  [com.arjuna.ats.jbossatx] ARJUNA032014: Stopping transaction recovery manager
10:54:55,010 INFO  [org.apache.catalina.core.StandardContext] Container org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/] has not been started
10:54:55,039 INFO  [org.apache.coyote.http11.Http11Protocol] Pausing Coyote HTTP/1.1 on http--127.0.0.1-8080
10:54:55,039 INFO  [org.apache.coyote.http11.Http11Protocol] Stopping Coyote HTTP/1.1 on http--127.0.0.1-8080
10:54:55,043 INFO  [org.jboss.as.controller] JBAS014774: Service status report
JBAS014776:    Newly corrected services:
      service jboss.jdbc-driver.mysql (new available)

10:54:55,044 INFO  [org.jboss.as] JBAS015950: JBoss AS 7.1.1.Final "Brontes" stopped in 47ms

I am new to JBoss and don't know how to fix this issue or to understand what is that I am doing wrong here

I think in your datasource you are referencing the driver mysql , but you named the driver com.mysql .

Try changing one the driver name to mysql .

Just a note: it is best to use the CLI to install the drivers and use the CLI or Web Console to build your datasources. The intention with AS7 is that these tools are used for all of your config and there are very few reasons why you should touch the XML yourself.

I had exactly the same mistake. Took me hours to find out how dumb it was.

In my case I was running jboss as a service under the jboss-as user, nice and easy. Except that when I created the mysql/main directory, along with the files within, I was under another user. No permissions there for jboss-as guy.

A simple chown on modules/ directory did the job.

First of all, your driver definition name doesn't match the driver name under the <datasource> definition. Replace <driver name="com.mysql" ... with <driver name="mysql" ... for it to work.

Second, have you added the module.xml file? It's not enough to copy the MySQL connector jar in the ./modules/com/mysql/main folder, you also have to add the module.xml file:

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

<module xmlns="urn:jboss:module:1.1" name="com.mysql">
  <resources>
    <resource-root path="mysql-connector-java-5.1.26-bin.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
  </dependencies>
</module>

Also, I had a strage similar problem when using the MySQL connector version 5.0.8, where the driver was not found / recognized. It disappeared when I switched to the newer 5.1.26 version.

确保您使用的是最新版本的mysql jdbc connector ,我通过更换最新的 mysql 连接器解决了我的相同问题

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM