JBoss: MySQL driver not found - java

I'm developing web application using MySQL under JBoss 7.1.1.
I have followed one of the tutorials to install MySQL driver on my server. I created appropriate directories in which I have placed driver:
modules
|--com
|--mysql
|--main
|--mysql-connector-java-5.1.18-bin.jar
|--module.xml
My module.xml looks as below:
<?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.18-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
I have also added datasource and driver in standalone.xml:
<datasources>
<datasource jndi-name="java:jboss/datasources/my_db" pool-name="MySqlDS">
<connection-url>jdbc:mysql://localhost:3306/my_db</connection-url>
<driver>com.mysql</driver>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<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>
</security>
<statement>
<prepared-statement-cache-size>32</prepared-statement-cache-size>
<share-prepared-statements>true</share-prepared-statements>
</statement>
</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>
</datasources>
Then and I try to inject it in my bean and use like that:
#Startup
#Singleton
public class StartupBean {
private static final Logger LOGGER = LogManager.getLogger(StartupBean.class);
#Resource(mappedName = "java:jboss/datasources/my_db")
private DataSource ds;
#PostConstruct
public void init() {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
LOGGER.error("MySQL driver not found!", e);
}
}
}
Unfortunately when I try to found driver i get:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
I have also tried not to check for driver and just call ds.getConnection(). It does not couse any exception. But when i try to invoke method on my connection I get:
java.lang.AbstractMethodError: org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6.getSchema()
And here is the question. What have I missed while configuring connection? DataSource is bind according to logs. I have tried also newer driver version (5.1.35-bin) but it didn't change anything. Version of my mysql db is 5.6.24.

Related

How to switch from default H2 DB of jBPM to another Database like MariaDB?

I've installed MariaDB connector in jBPM 7.53 Final with .jar file and configured MariaDB database locally. Checked in management console and saw that datasources and JDBC connectors look good (MariaDBDS is enabled), but an error showing in runtime "Boot errors occurred during the start of server".
Failure description: {"WFLYCTL0412: Required services that are not
installed:" =>
["jboss.jdbc-driver.mariadb-java-client-2_7_1_jar"],"WFLYCTL0180:
Services with missing/unavailable dependencies" =>
["jboss.driver-demander.java:jboss/MariaDBDS is missing
[jboss.jdbc-driver.mariadb-java-client-2_7_1_jar]","org.wildfly.data-source.MariaDBDS
is missing [jboss.jdbc-driver.mariadb-java-client-2_7_1_jar]"]}
Missing dependencies: jboss.driver-demander.java:jboss/MariaDBDS is
missing [jboss.jdbc-driver.mariadb-java-client-2_7_1_jar]
org.wildfly.data-source.MariaDBDS is missing
[jboss.jdbc-driver.mariadb-java-client-2_7_1_jar]
I have configured MariaDB Java connector in the jBPM standalone.xml
<subsystem xmlns="urn:jboss:domain:datasources:5.0">
<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="true" jndi-name="java:jboss/MariaDBDS" pool-name="MariaDBDS" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:mariadb://localhost:3306/mysql</connection-url>
<driver-class>org.mariadb.jdbc.Driver</driver-class>
<driver>mariadb-java-client-2.7.1.jar</driver>
<security>
<user-name>root</user-name>
<password>admin</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
<validate-on-match>true</validate-on-match>
<background-validation>false</background-validation>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
</validation>
</datasource>
<drivers>
<driver name="mariadb" module="org.mariadb">
<xa-datasource-class>org.mariadb.jdbc.MariaDbDataSource</xa-datasource-class>
</driver>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
and I have copied the MariaDB Java connector to JBPM_HOME/modules/com/mariadb/main/mariadb-java-client-2.7.1.jar and configured the module.xml like this:
<module xmlns="urn:jboss:module:1.1" name="org.mariadb">
<resources>
<resource-root path="mariadb-java-client-2.7.1.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
Also, in Business-Central to new process instance appeared this attention:
enter image description here
What I am missing or change in these steps? Any idea if jBPM works with the external DB or not?
#KrenarR have you set up these properties under system-properties as well?
<property name="org.kie.server.persistence.ds" value="java:jboss/MariaDBDS"/>
<property name="org.kie.server.persistence.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
You can also add the driver as a core module by means of jboss_cli:
module add --name=org.mariadb --resources=mariadb-java-client-2.7.1.jar --dependencies=javax.api,javax.transaction.api
Also check this line in the datasource:
<driver>mariadb-java-client-2.7.1.jar</driver>
I think it should be just the driver name you have defined:
<driver>mariadb</driver>
You can refer to the documentation Switch to another database
from jbpm.org for detailed steps.

connection pool on jboss 7.0.2 don't work

I trying to do a pool connection on JBoss, I saw many things on the internet about this, but nothing work....
<?xml version="1.0" encoding="UTF-8"?>
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/db_test" pool-name="db_testDS">
<connection-url>jdbc:sqlserver://----------;databaseName=db_test</connection-url>
<driver>MSSQL</driver>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>30</max-pool-size>
<prefill>true</prefill>
</pool>
<security>
<user-name>us***</user-name>
<password>mo***</password>
</security>
</datasource>
<drivers>
<driver name="MSSQL" module="com.microsoft.sqlserver.jdbc.SQLServerDriver">
<xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
when I enter on JBoss admin db_test don't apear
what is worng?
Please refer the link.
https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6/html/Administration_and_Configuration_Guide/Example_Microsoft_SQLServer_Datasource1.html
Select appropriate database drivers and you will get the correct configuration.
Following is the configuration for MS SQL Server
The example below is a Microsoft SQLServer datasource configuration. The datasource has been enabled, a user has been added, and validation options have been set.
<datasources>
<datasource jndi-name="java:/MSSQLDS" pool-name="MSSQLDS">
<connection-url>jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=MyDatabase</connection-url>
<driver>sqlserver</driver>
<security>
<user-name>admin</user-name>
<password>admin</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLValidConnectionChecker"></valid-connection-checker>
</validation>
</datasource>
<drivers>
<driver name="sqlserver" module="com.microsoft">
<xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerXADataSource</xa-datasource-class>
</driver>
</datasources>
================================================================================
The example below is a module.xml file for the Microsoft SQLServer datasource above.
================================================================================
<module xmlns="urn:jboss:module:1.1" name="com.microsoft">
<resources>
<resource-root path="sqljdbc4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>

Add new Datasource (mysql) wildfly

I'm trying to add new datasource mysql jdbc driver to my wildfly server
I created folder wildfly.x.x.x/modules/system/layers/base/com/mysql/main
I've got here jdbc jar file and module.xml
<module xmlns="urn:jboss:module:1.3" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-5.1.34-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
then added dataresource code into standalone-full.xml (under datareources tag)
<datasource jndi-name="java:jboss/datasources/MySQLDS" pool-name="MySQLDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/test</connection-url>
<driver>MySQLDriver</driver>
<security>
<user-name>root</user-name>
<password></password>
</security>
</datasource>
but when i go to wildfly control panel http://localhost:9990/console/
dataresource doesnt appear , what did i missed?
also i'm trying to add it manually from interface i'v got this error
Unexpected HTTP response: 500
Request
{
"address" => [
("subsystem" => "datasources"),
("data-source" => "mysql")
],
"operation" => "test-connection-in-pool"
}
Response
Internal Server Error
{
"outcome" => "failed",
"failure-description" => "JBAS010440: failed to invoke operation: JBAS010447: Connection is not valid",
"rolled-back" => true
}
Did you add a driver definition? Your datasources subsystem should look something like this:
<subsystem xmlns="urn:jboss:domain:datasources:2.0">
<datasources>
<datasource jndi-name="java:/jdbc/myds" pool-name="myds" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost/mydb</connection-url>
<driver>mysql</driver>
<security>
<user-name>foo</user-name>
<password>bar</password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
The driver element in the data source definition must reference a driver element by name. The module attribute must match the name of your MySQL driver module.
Actually I meet the same problem (I could add the datasources and test connection successfully before) So I'm just confused and I find a way works for me:)
See my services and I find it stopped,and I started it then tried again,It works well again! Even though your service does not stop, maybe just restart it.
I have to say it may not work for you if you never success to connect before,good luck~
There are three ways using which you can simply create datasource into wildfly
Using admin console
Manually adding into standalone.xml
Creating datasource file that is xml file.
Go to WildFly directory/standalone/deployments
Simplest way to create datasource xml with following content
<datasources xmlns="http://www.jboss.org/ironjacamar/schema">
<datasource jndi-name="APP_DS" pool-name="APP_DS" enabled="true" use-ccm="false">
<connection-url>jdbc:mysql://localhost:3306/DB_NAME</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver>mysql</driver>
<!-- sql to call when connection is created -->
<new-connection-sql>SELECT 1</new-connection-sql>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>50</max-pool-size>
</pool>
<security>
<user-name>username</user-name>
<password>password</password>
</security>
<!-- sql to call on an existing pooled connection when it is obtained from pool -->
<validation>
<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
</validation>
<timeout>
<blocking-timeout-millis>300000</blocking-timeout-millis>
<idle-timeout-minutes>5</idle-timeout-minutes>
</timeout>
<statement>
<track-statements>true</track-statements>
</statement>
</datasource>
</datasources>
Also create the database that you will use. Sometimes the reason for this error is that the database is missing.

Not able to connect to MySql database while running the web application in JBOSS

I have a web application which runs successfully in Tomcat server and it uses MySql database. Now, I am trying to run it on JBOSS 7, but the DB connection is not happening. No error in C:\jboss-eap-6.2\standalone\log\server.log file. Not sure where else can I see some error messages.
My standalone.xml
<subsystem xmlns="urn:jboss:domain:datasources:1.1">
<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</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<datasource jta="true" jndi-name="java:jboss/datasources/Matix" pool-name="Matix" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/Matix</connection-url>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password>password</password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="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>
</datasources>
</subsystem>
**My module.xml under the path: C:\jboss-eap-6.2\modules\com\mysql\main (Also, not sure if the path is correct) **
<module xmlns="urn:jboss:module:1.0" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-5.0.8-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
I put mysql-connector-java-5.0.8-bin.jar under the path C:\jboss-eap-6.2\modules\com\mysql\main
I have not done any changes in my web.xml and my JDBC Connection code. Are those required?
What else I am missing? Please help.
EDIT
** part of Java Code **
public class LoginAction implements ServletResponseAware {
public String login() {
String result_type_Is = "";
result_type_Is = this.checkAuthorization(con);
PrintWriter out = response.getWriter();
response.setContentType("text/plain");
out.write(result_type_Is);
}
}
private String checkAuthorization(Connection con) {
try {
// Checking DB Authentication
// Returns SUCCESS or WRONG
}
catch (Exception e) {
//..........
return FAIL;
} finally {
// Closing all connections
}
return result;
}
JS Code
var display = login_request.responseText;
if (display == "SUCCESS") {
// redirect to home page
}
else{
//Show DB conn failure msg
}

Jboss mysql datasource

im trying to create a new datasource and "lookup" from java code.
First i created folder, jboss-as-7.1.0.Final\modules\com\mysql\main and copy to there 2 files.
mysql-connector-java-5.1.14-bin and module.xml
My module.xml contains
<?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.14-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
Second i added in file standalone.xml,this..
<datasource jndi-name="java:jboss/datasources/MySqlDS" pool-name="MySqlDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://127.0.0.1:3306/myTable</connection-url>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password>root</password>
</security>
</datasource>
<drivers>
<driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
And last, i tried to call it from java code like this:
DataSource ds = (DataSource) ctx.lookup("jboss/datasources/MySqlDS");
connection = ds.getConnection();
But got this error..
javax.naming.NameNotFoundException: jboss/datasources/MySqlDS -- service jboss.naming.context.java.jboss.datasources.MySqlDS
Anyway,when i started my jboss server i got and error,too
New missing/unsatisfied dependencies:
service jboss.jdbc-driver.mysql (missing) dependents: [service jboss.data-source.java:/MySqlDS]
Please try using
DataSource ds = (DataSource) ctx.lookup("java:jboss/datasources/MySqlDS");
It's probably happened because the Data Source is not configured properly. I had a similar issue but when I configured it using JBoss Admin Console, it worked. Also try to check if you have .jar extension in your module.xml.
Try following this link step by step. It works perfectly.

Categories