: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
Related
I am trying to get to the underlaying Oracle connection in my WebApp on a JBoss Wildly 8.1 server.
I get an exception when I try to do the unwrap:
connection.unwrap(OracleConnection.class);
Throws
java.sql.SQLException: Not a wrapper for: oracle.jdbc.OracleConnection
The connection's class turns out to be com.sun.proxy.$Proxy37
This is my configuration in standalone.xml:
<subsystem xmlns="urn:jboss:domain:datasources:2.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/myds" pool-name="MyPool" enabled="true">
<connection-url>jdbc:oracle:thin:#//host:152x/blabla</connection-url>
<driver>Oracle11g</driver>
<security>
<user-name>xxx</user-name>
<password>yyy</password>
</security>
</datasource>
<drivers>
<driver name="Oracle11g" module="com.oracle.ojdbc6">
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
</driver>
</drivers>
</datasources>
</subsystem>
How can I get to the OracleConnection?
Edit: I have configured the oracle driver in the standalone.xml and the driver is added in the modules folder. In order to be able to get my code compiled, I have added a dependency in my pom-file to the driver as well. No idea if this is part of the cause.
Thanks
I found the solution!
When using this statement I can get to the OracleConnection object:
(oracle.jdbc.driver.OracleConnection) conn.getMetaData().getConnection();
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
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.
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&useUnicode=yes&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&useUnicode=true&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
I have some applications running on JBoss 4.2.2, JBoss 5.1 and WildFly 8.1.0. All these applications use connection pooling. My datasources are something like that:
<datasource jta="false" jndi-name="java:/datasource/myawesomeds" pool-name="MyAwesomeDS" enabled="true" use-ccm="false">
<connection-url>jdbc:oracle:thin:#myserver.example.com:1521:oracle_service</connection-url>
<driver-class>oracle.jdbc.OracleDriver</driver-class>
<driver>ojdbc6.jar</driver>
<security>
<user-name>username</user-name>
<password>MyPassWord</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
As you can see, I use Oracle Database. The server version is 10g. When Oracle DB going down for a few minutes all my applications on JBoss and WildFly start showing SQLException: Closed Connection.
My question: Is it normal? Why JBoss and WildFly don't check the connections to verify this?
Yes, this is normal.
You can however define that wildfly/jboss should verify the connection when fetching it from the connection pool. All your connections will be invalid, so normally it should create a new connection for you if you defined a minimum number of connections that should be present.