[英]Jboss connection pool doesn't connect with the DataBase
I am using JBoss 7.1, and I'm trying to create a Database Connection Pool through Application Server. 我正在使用JBoss 7.1,并且正在尝试通过Application Server创建数据库连接池。 I'm using a mysql DB, but I tried also with a Postgre database and the error is just the same. 我正在使用mysql DB,但我也尝试使用Postgre数据库,并且错误是相同的。 Everything seems to be OK, but when I try to access to the application, it appears an error on console that advises me that the connection with the database was failed. 一切似乎都正常,但是当我尝试访问该应用程序时,控制台上出现一个错误,提示我与数据库的连接失败。 My code is the following: 我的代码如下:
My Jboss standalone.xml. 我的Jboss standalone.xml。
<datasource jndi-name="java:jboss/jdbc/exampleDS" pool-name="jdbc/exampleDS" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:mysql://127.0.0.1:3306/example?useSSL=false</connection-url>
<driver>mysql-connector-java-5.1.43-bin.jar</driver>
<pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>100</max-pool-size>
<prefill>true</prefill>
</pool>
<security>
<user-name>root</user-name>
<password>password</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
</validation>
</datasource>
<driver name="mysql-connector-java-5.1.43-bin.jar" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlDataSource</xa-datasource-class>
</driver>
My web.xml 我的web.xml
<resource-ref>
<description>example</description>
<res-ref-name>jdbc/exampleDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
My javacode 我的javacode
private ServiceLocator() {
try {
this.initCtx = new InitialContext();
this.envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource)
envCtx.lookup("jdbc/exampleDS");
} catch (NamingException e) {
ApplicationException apRE = new ApplicationException(ErrorCode.E_JDNI001, e);
LogService.getLog().fatal(apRE.getMessage(), apRE);
throw apRE;
}
}
Finally, when I start my jboss server, none error appears, but the console said that the tables of my DB don't exist. 最后,当我启动我的jboss服务器时,没有错误出现,但是控制台说我的数据库表不存在。
I appreciate help <3 我感谢帮助<3
I had fixed the error. 我已经修复了错误。 First thing to do is creating a jboss-web.xml where web.xml, in my case, webapp/WEB-INF. 首先要做的是创建一个jboss-web.xml,其中web.xml(在我的情况下为webapp / WEB-INF)。 It must be similar to the following: 它必须类似于以下内容:
<jboss-web>
<resource-ref>
<res-ref-name>jdbc/exampleDS</res-ref-name>
<jndi-name>java:jboss/jdbc/exampleDS</jndi-name>
</resource-ref>
</jboss-web>
Once that is created, we must create a module.xml inside of modules->com->mysql->main, containing the following: 创建之后,我们必须在modules-> com-> mysql-> main内创建一个module.xml,其中包含以下内容:
<?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.43-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
You have to insert also, the .jar that you used also inside of the main dir. 您还必须在主目录中插入也使用的.jar。 Regarding the javacode, you need to change the initCtx.lookup("java:comp/env"); 关于Java代码,您需要更改initCtx.lookup(“ java:comp / env”); for this: initCtx.lookup("java:"); 为此: initCtx.lookup(“ java:”);
That's all :) 就这样 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.