在JBoss中设置Mysql连接器模块

时间:2013-10-25 10:40:23

标签: netbeans jboss persistence datasource mysql-connector

我在本地JBoss的MySQL模块中遇到了一些问题。

在$ JBOSS_HOME中我创建了com / mysql / main 在那里,我删除了mysql-connector-java-5.1.26-bin.jar和module.xml

module.xml

然后我配置了我的数据源。

datasouce config in standalone.xml

在Netbeans项目中,persistence.xml通过Persistence Unit向导配置为附加,Netbeans自动识别配置的数据源,这很酷。

persistence.xml

现在的问题是,当我想“从数据库创建实体类”时,我收到此错误。

enter image description here

我已经在网上查了一下。我认为我有一个很好的配置,但这个错误仍然存​​在。

Netbeans:7.3.1; Mysql连接器:5.1.26; App Server:JBoss EAP 6.1.0; Mysql:5.6.14; Windows 7的; Java 7

请告知。 感谢。

2 个答案:

答案 0 :(得分:0)

在$ JBOSS_HOME中我创建了com / mysql / main在那里,我删除了mysql-connector-java-5.1.26-bin.jar和module.xml

您能否确保该文件夹位于$ JBOSS_HOME / modules location

答案 1 :(得分:0)

我今天找到了答案,

只需设置驱动程序类和驱动程序相同的名称 com.mysql.jdbc.Driver

<driver-class>com.mysql.jdbc.Driver</driver-class>
    <driver>com.mysql.jdbc.Driver</driver>
    <pool>
        <min-pool-size>10</min-pool-size>
        <max-pool-size>100</max-pool-size>
        <use-strict-min>true</use-strict-min>
        <flush-strategy>IdleConnections</flush-strategy>
    </pool>
    <security>
        <user-name>root</user-name>
        <password>root</password>
    </security>

并创建jboss-ds xml文件并将其放入-ejb \ src \ main \ setup

<?xml version="1.0" encoding="UTF-8"?>
<datasources>    
    <datasource jta="false" jndi-name="java:/MysqlDS" pool-name="MysqlDS" enabled="true" use-ccm="false" statistics-enabled="false">
        <connection-url>jdbc:mysql://localhost:3306/dmbs?zeroDateTimeBehavior=convertToNull&amp;amp;useUnicode=yes&amp;amp;characterEncoding=UTF-8</connection-url>
        <driver-class>com.mysql.jdbc.Driver</driver-class>
        <driver>com.mysql.jdbc.Driver</driver>
        <pool>
            <min-pool-size>10</min-pool-size>
            <max-pool-size>100</max-pool-size>
            <use-strict-min>true</use-strict-min>
            <flush-strategy>IdleConnections</flush-strategy>
        </pool>
        <security>
            <user-name>root</user-name>
            <password>root</password>
        </security>
        <validation>
            <validate-on-match>false</validate-on-match>
            <background-validation>false</background-validation>
        </validation>
        <timeout>
            <set-tx-query-timeout>false</set-tx-query-timeout>
            <blocking-timeout-millis>0</blocking-timeout-millis>
            <idle-timeout-minutes>3</idle-timeout-minutes>
            <query-timeout>0</query-timeout>
            <use-try-lock>0</use-try-lock>
            <allocation-retry>0</allocation-retry>
            <allocation-retry-wait-millis>0</allocation-retry-wait-millis>
        </timeout>
        <statement>
            <track-statements>true</track-statements>
            <share-prepared-statements>false</share-prepared-statements>
        </statement>    
    </datasource>      
</datasources>

和我的standalone.xml配置

<datasources>
                <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
                    <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
                    <driver>h2</driver>
                    <security>
                        <user-name>sa</user-name>
                        <password>sa</password>
                    </security>
                </datasource>
                <datasource jta="false" jndi-name="java:/MysqlDS" pool-name="MysqlDS" enabled="true" use-ccm="false" statistics-enabled="false">
                    <connection-url>jdbc:mysql://localhost:3306/dmbs?zeroDateTimeBehavior=convertToNull&amp;amp;useUnicode=yes&amp;amp;characterEncoding=UTF-8</connection-url>
                    <driver-class>com.mysql.jdbc.Driver</driver-class>
                    <driver>com.mysql.jdbc.Driver</driver>
                    <pool>
                        <min-pool-size>10</min-pool-size>
                        <max-pool-size>100</max-pool-size>
                        <use-strict-min>true</use-strict-min>
                        <flush-strategy>IdleConnections</flush-strategy>
                    </pool>
                    <security>
                        <user-name>root</user-name>
                        <password>root</password>
                    </security>
                    <validation>
                        <validate-on-match>false</validate-on-match>
                        <background-validation>false</background-validation>
                    </validation>
                    <timeout>
                        <set-tx-query-timeout>false</set-tx-query-timeout>
                        <blocking-timeout-millis>0</blocking-timeout-millis>
                        <idle-timeout-minutes>3</idle-timeout-minutes>
                        <query-timeout>0</query-timeout>
                        <use-try-lock>0</use-try-lock>
                        <allocation-retry>0</allocation-retry>
                        <allocation-retry-wait-millis>0</allocation-retry-wait-millis>
                    </timeout>
                    <statement>
                        <track-statements>true</track-statements>
                        <share-prepared-statements>false</share-prepared-statements>
                    </statement>
                </datasource>
                <drivers>
                    <driver name="com.mysql.jdbc.Driver" module="com.mysql.jdbc">
                      <driver-class>com.mysql.jdbc.Driver</driver-class>
                      <!--  <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>-->
                    </driver>
                    <driver name="h2" module="com.h2database.h2">
                        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                    </driver>
                </drivers>
            </datasources>

我的module.xml文件 C:\ wildfly-9.0.0 \模块\ SYSTEM \层\基\ COM \ MySQL的\ JDBC \主 并且靠近mysql驱动程序jar

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.mysql.jdbc">
        <resources>
            <resource-root path="mysql-connector-java-5.1.32-bin.jar"/>
        </resources>
        <dependencies>
            <module name="javax.api"/>
            <module name="javax.transaction.api"/>
</dependencies>
</module>