Wildfly and auto reconnect to the database - java

I've got a client, a server and a database. The client communicates with the server via a EJB remote interfaces. As the server - I use a Wildfly 8.2.0. As the database - I use a MySQL. The server communicates with the MySQL via a JPA/Hibernate. When I turn off the MySQL server - the Wildfly throws an exception, of course. But when I turn on the MySQL again - the Wildfly still throws the same ERROR. I've to turn off the Wildfly and turn it back that the Wildfly reconnect to the database.
How to set auto reconnect in the Wildfly?
I tried to set auto reconnect in a connection URL: jdbc:mysql://localhost/db?autoReconnect=true&useUnicode=yes&characterEncoding=UTF8 and i tried to add to the standalone-full.xml file which i use, this line: <check-valid-connection-sql>select 1</check-valid-connection-sql>, but both solutions don't work.
standalone-full.xml:
<!-- ... -->
<datasource jta="true" jndi-name="java:jboss/datasources/MySQLDS" pool-name="MySQLDS" enabled="true" use-ccm="true">
<connection-url>jdbc:mysql://localhost/db?autoReconnect=true&amp;useUnicode=yes&amp;characterEncoding=UTF8</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver>mysqlDriver</driver>
<security>
<user-name>user</user-name>
<password>***</password>
</security>
<validation>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
<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>0</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>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
<drivers>
<driver name="mysqlDriver" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.Driver</xa-datasource-class>
</driver>
</drivers>
<!-- ... -->

This working on Wildfly 8.1:
<datasource jta="true" jndi-name="java:jboss/datasources/xxxdb" pool-name="xxxxDB" enabled="true" use-ccm="false">
<connection-url>jdbc:mysql://localhost:3306/xxxdb?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF-8</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver>mysql-connector-java-5.1.26-bin.jar</driver>
<security>
<user-name>xxxuser</user-name>
<password>xxxpassword</password>
</security>
<validation>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
<validate-on-match>false</validate-on-match>
<background-validation>true</background-validation>
<background-validation-millis>10000</background-validation-millis>
</validation>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>

I solved this problem by changing the validate-on-match value to true in my standalone-full.xml file:
<validate-on-match>true</validate-on-match>

You can set <background-validation> to true , because this option has better performance , and set <validate-on-match> to false

Related

Wildfly 10 failing to load MySQL XA driver on startup

I have a web application I am deploying in wildfly-10.0.0. It requires a mysql xa driver. I have the following error:
2015-10-13 12:25:37,979 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 33) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "com.mysql")
]) - failure description: "WFLYJCA0041: Failed to load module for driver [com.mysql]"
The modules directory is as follows:
Directory of C:\Users\rball\Documents\Dev\WildFly\wildfly-10.0.0.CR1\modules\sy
stem\layers\base\com\mysql\main
10/13/2015 11:32 AM <DIR> .
10/13/2015 11:32 AM <DIR> ..
10/13/2015 12:25 PM 1,575 module.xml
03/17/2015 05:21 AM 968,670 mysql-connector-java-5.1.35-bin.jar
The module.xml file is:
<?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.35-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
I added the driver and datasource to the datasources section of standalone.xml:
<xa-datasource jndi-name="java:/jdbc/MyXaDS" pool-name="MyXaDSPool" enabled="true" use-ccm="false">
<xa-datasource-property name="URL">
jdbc:mysql://localhost:3306/temp?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8
</xa-datasource-property>
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
<driver>com.mysql</driver>
<xa-pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>20</max-pool-size>
<is-same-rm-override>false</is-same-rm-override>
<interleaving>false</interleaving>
<pad-xid>false</pad-xid>
<wrap-xa-resource>false</wrap-xa-resource>
</xa-pool>
<security>
<user-name>root</user-name>
<password>password</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
<background-validation-millis>1000</background-validation-millis>
</validation>
<statement>
<prepared-statement-cache-size>0</prepared-statement-cache-size>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</xa-datasource>
<drivers>
<driver name="com.mysql" module="com.mysql">
<driver-class>com.mysql.jdbc.Driver</driver-class>
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
The error you get means that wildfly expects a module called com.mysql but it doesn't exist or it isn't registered under that name.
You are missing one step, which is registering the datasource jdbc driver. The first step of course being adding the mysql-connector-java-5.1.35-bin.jar file and module.xml file in WILDFLY_HOME\modules\system\layers\base\com\mysql\main.
To get rid of your error, stop wildfly, delete the the driver declaration in your standalone.xml by removing these lines; We'll let the /subsystem command create this entry.
<driver name="com.mysql" module="com.mysql">
<driver-class>com.mysql.jdbc.Driver</driver-class>
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
Open your command prompt and navigate to WILDFLY_HOME\bin\ and run the following commands.
Connect to jboss cli by running : jboss-cli.bat --connect . In case your management console is running on a different port say , localhost:9991, use jboss-cli.bat --connect --controller=127.0.0.1:9991
Then register the jdbc-driver with the following command
/subsystem=datasources/jdbc-driver=com.mysql:add(driver-name=com.mysql,driver-module-name=com.mysql,driver-xa-datasource-class-name=com.mysql.jdbc.jdbc2.optional.MysqlXADataSource)
You should get the response {"outcome" => "success"} if this was successful.
From there, reload your server and you should get rid of that error.
I got pointers from This link
I'm not really sure what the issue could be. The message isn't very informative.
That said the following add-mysql.cli script worked for me.
module add --name=com.mysql --resources=~/Downloads/mysql-connector-java-5.1.37/mysql-connector-java-5.1.37-bin.jar --dependencies=javax.api,javax.transaction.api
batch
/subsystem=datasources/jdbc-driver=com.mysql:add(driver-name=com.mysql, driver-module-name=com.mysql, driver-xa-datasource-class-name=com.mysql.jdbc.jdbc2.optional.MysqlXADataSource)
/subsystem=datasources/xa-data-source=mysql:add(driver-name=com.mysql, jndi-name="java:/jdbc/MySQLXA", enabled=true)
/subsystem=datasources/xa-data-source=mysql/xa-datasource-properties=URL:add(value="jdbc:mysql://localhost:3306/temp?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8")
run-batch
I didn't write all the properties defined in your data source configuration, but this did work.
WildFly 10 has some change in jca caused CLI create xa ds have some issue.
https://issues.jboss.org/browse/WFLY-6773
https://issues.jboss.org/browse/WFLY-6789
https://issues.jboss.org/browse/WFLY-6774
But create xa datasouces use below commands works
xa-data-source add --name=MariaDBXADS --driver-name=mariadb-xa --jndi-name=java:jboss/datasources/MariaDBXADS --user-name=jdv_user --password=jdv_pass --use-java-context=true --xa-datasource-properties=[DatabaseName=>products, PortNumber=>3306, ServerName=>localhost]
WILDFLY 10 using MySQL 5.7
Follow these steps: comment or delete exampleds in standalone.xml
into jboss-cli.bat --connect
After execute command:
[standalone#localhost:9990 /] /subsystem=datasources/jdbc-driver=mysql:add(driver-name=mysql,driver-module-name=com.mysql,driver-xa-datasource-class-name=com.mysql.jdbc.jdbc2.optional.MysqlXADataSource)
should be ok.
This modified standalone.xml, then add:
<datasources>
<!--
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-
<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 jndi-name="java:/mysql" pool-name="mysqlDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/wildfly</connection-url>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password>jdfoxito10</password>
</security>
</datasource>
<drivers>
<driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
should look like!
and module.xml put in
\java\server\wildfly-10.1.0.Final\modules\system\layers\base\com\mysql\main
mysql-connector-java-5.1.40-bin.jar (come installer mysql-installer-community-5.7.15.0.msi) module.xml
and content from module.xml like:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-5.1.40-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
and ready, JAVA_HOME should be ok

How does JBoss 7.1.1 manage connection to different schemas of the same database

So I have a servlet where I login to a database with Datasource(where I only pass the JNDI name) with a default schema(which was set in the JBoss management console) but later on I need to connect on the same database with another schema in order to get some texts.
How does JBoss manage this ? Can I provide the later schema and password somehow in the java code ?
În standalone.xml you declare all your datasources. Those connections can be picked up by jndi at runtime by looking up on an InitialContext instance.
When using JNDI to form connections, you will need to configure the new datasource within the management console or the standalone.xml file. This will simply be a new datasource, with a connection URL going to the same database, but pointing to a new schema.
Example output in the standalone.xml:
<datasource jta="false" jndi-name="java:/firstDS" pool-name="firstDS" enabled="true" use-ccm="false">
<connection-url>jdbc:oracle:thin:#devdb:1521:SCHEMA_1</connection-url>
<driver-class>oracle.jdbc.OracleDriver</driver-class>
<driver>oracle</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
...
<datasource jta="false" jndi-name="java:/secondDS" pool-name="secondDS" enabled="true" use-ccm="false">
<connection-url>jdbc:oracle:thin:#devdb:1521:SCHEMA_2</connection-url>
<driver-class>oracle.jdbc.OracleDriver</driver-class>
<driver>oracle</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
Now in the second part of your application you will just refer to that second datasource's JNDI name when forming the connection.

How do i set up datasource on Jboss 6 EAP for as400 db2?

I am trying to setup a jboss 6.3 data-source to an ibm as400
jboss 6.3 is running on a windows server 2012 VM
java 1.8.0_31 64 bit
i am getting this error in the console on start up of jboss
1
4:02:09,332 INFO [org.jboss.as.controller] (Controller Boot Thread)
JBAS014774: Service status report JBAS014775: New
missing/unsatisfied dependencies:
service jboss.jdbc-driver.as400 (missing) dependents: [service jboss.driver-demander.java:jboss/datasour ces/PPSDB, service
jboss.data-source.java:jboss/datasources/PPSDB]
this is my module.xml i have it and the driver jt400.jar in
D:\Program Files\jboss-eap-6.3\modules\com\ibm\as400\main
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<module xmlns="urn:jboss:module:1.0" name="com.ibm.as400">
<resources>
<resource-root path="jt400.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
This is the datasource subsystem from my Standalone.xml
<subsystem xmlns="urn:jboss:domain:datasources:1.1">
<datasources>
<datasource jndi-name="java:jboss/datasources/PPSDB" pool-name="java:jboss/datasources/PPSDB_Pool" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:as400://development.ad.company.com/JKCDRIVER;DB_CLOSE_DELAY=-1</connection-url>
<driver-class>com.ibm.as400.access.AS400JDBCDriver</driver-class>
<driver>as400</driver>
<pool>
<min-pool-size>2</min-pool-size>
<max-pool-size>20</max-pool-size>
<prefill>true</prefill>
</pool>
<security>
<user-name>user</user-name>
<password>password</password>
</security>
<validation>
<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
<use-fast-fail>false</use-fast-fail>
</validation>
</datasource>
<drivers>
<driver name="as400" module="com.ibm.as400"/>
</drivers>
</datasources>
</subsystem>
i have found a few different examples for setting up an as400 data-source on old versions of jboss, but the tags seem to have changed, and i have not been able to figure out how to get this working
https://developer.jboss.org/wiki/SetUpADB2Datasource
any help would be greatly appreciated
I moved the driver-class tag inside the driver tag like suggested in the answer below, removed the data source from the standalone.xml, then using the jboss web console added the data source. That generated this in the standalone.xml
<datasource jta="false" jndi-name="java:/jdbc/ppsdb" pool-name="mypool" enabled="true" use-ccm="false">
<connection-url>jdbc:as400://development.ad.company.com/JKCDRIVER</connection-url>
<driver-class>com.ibm.as400.access.AS400JDBCDriver</driver-class>
<driver>as400</driver>
<security>
<user-name>user</user-name>
<password>pass</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>0</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>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
now its working great, thanks
Make sure your 'jt400.jar' is on the path \modules\com\ibm\as400\main
Your module.xml should read like
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.ibm.as400">
<resources>
<resource-root path="jt400.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
In your Driver tag add the driver-class child
<driver name="as400" module="com.ibm.as400">
<driver-class>com.ibm.as400.access.AS400JDBCDriver</driver-class>
</driver>

auto reconnect in jboss-as-7.1.1.Final

:D Hi there
I have installed jboss-as-7.1.1.Final for my webapp.
Its running normally for every activity except one thing.
When ms sql server services was restarted or stopped a while, my jboss wouldn't rebuild the connection to datasource automatically.
I must restarting jboss manually, so it can rebuild the connection again.
What i want is jboss autoreconnecting when that problem happen again.
Below is my datacource config, could you tell me please what i am miss?
....
<datasource jndi-name="java:jboss/MsSqlDS" pool-name="MsSqlDS" enabled="true" use-java-context="true" use-ccm="false">
<connection-url>jdbc:sqlserver://localhost:1433;databaseName=dummy</connection-url>
<driver>sqlserver2008</driver>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>50</max-pool-size>
<prefill>false</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
<user-name>sa</user-name>
<password>*******</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLValidConnectionChecker"/>
</validation>
</datasource>
....
note :
i have try this
<validation>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
</validation>
based on Is there any way to have the JBoss connection pool reconnect to Oracle when connections go bad?
but still not work for me
Thanks & Regards
Newbie

JBoss 7 MySQL datasource issue

I'm trying to create a datasource in JBOSS 7.
My standalone.xml excerpts:
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasource jndi-name="MySqlDS" pool-name="MySqlDS" enabled="true" jta="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:mysql://localhost:3306/sampledb</connection-url>
<driver>mysql</driver>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<pool>
<prefill>true</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
<user-name>root</user-name>
<password>matrix</password>
</security>
</datasource>
<drivers>
<driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
and I have created module/com/mysql/main directory and have put mysql jar there along with module.xml which is as below:
<module xmlns="urn:jboss:module:1.0" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-3.0.17-ga-bin.jar"/>
<!-- Insert resources here -->
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
and my persistence.xml uses this datasource
<jta-data-source>java:/MySqlDS</jta-data-source>
But the server start throws the error message as below.
New missing/unsatisfied dependencies:
service jboss.jdbc-driver.mysql (missing)
Could you please help ?
Thanks.
This will help you to fix the problem.
Jboss and mysql connector
See https://zorq.net/b/2011/07/12/adding-a-mysql-datasource-to-jboss-as-7/
Is the version of driver. Change for a new version. Believe, is only it!!!
I changed the driver mysql-connector-java-5.0.4-bin.jar for mysql-connector-java-5.1.25-bin.jar, then the problem is solved.
For me, after checking over and over that all of the module.xml and standalone.xml parameters where right. I realised i was using mysql-connector-java-xxx-bin.jar ...Changed it to a non bin jar and it MAGICALLY worked :D

Categories

Resources