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.
Related
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>
I am trying to configure a MariaDB datasource on Wildfly. This seems like it should be a simple operation, but I can't seem to get the datasource module to load properly. I have added the maria-java-client-1.1.8.jar archive and a module.xml file to the wildfly-8.2.0.Final/modules/com/mariadb/main directory. The module.xml file is as follows:
<module xmlns:"urn:jboss:module:1.1" name="com.mariadb">
<resources>
<resource-root path="mariadb-java-client-1.1.8.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
I have also added a driver entry to the standalone.xml file as follows:
<subsystem xmlns="urn:jboss:domain:datasources:2.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>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="mariadb" module="com.mariadb"/>
</drivers>
</datasources>
</subsystem>
Note that I have only included the driver entry for now. I will add the datasource entry after I get the module to load properly.
Now when I startup the server I get the following error:
14:14:46,570 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 26) JBAS014613: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "mariadb")
]) - failure description: "JBAS010441: Failed to load module for driver [com.mariadb]"
According to everything that I have read, this is the proper way to configure the driver, but it is not working for me. Does anyone know what I am doing wrong?
Thanks in advance for your help!
The first line of your module.xml has a typo (you use a colon instead of equals in xmlns=...):
Your version:
<module xmlns:"urn:jboss:module:1.1" name="com.mariadb">
Correct version:
<module xmlns="urn:jboss:module:1.3" name="com.mariadb">
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.
I am trying to upgrade to JBoss 7; however, my datasource is not creating a connection. I did not deploy any WAR files. I am testing the connection by using the admin console. In standalone.xml, I configured the datasource as follows:
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasource jta="false" jndi-name="java:jboss/projectDS" pool-name="projectDS" enabled="true">
<connection-url>jdbc:oracle:thin:#mcc-67-150.usae.ABC.com:1521:test</connection-url>
<driver-class>oracle.jdbc.OracleDriver</driver-class>
<driver>ojdbc6</driver>
<security>
<user-name>XXX</user-name>
<password>XXX</password>
</security>
</datasource>
<drivers>
<driver name="ojdbc6" module="com.oracle" />
</drivers>
</datasources>
</subsystem>
The ojdbc6.jar driver is in the following folder %JBOSS_HOME%\modules\com\oracle\main. The entry in my module.xml reads as follows:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.oracle">
<resources>
<resource-root path="ojdbc6.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
The error that I receive in my server log when I test the connection from the admin console is:
07:47:11,863 WARN [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool]
(HttpManagementService-threads - 4) IJ000604: Throwable while attempting to get
a new connection: null: javax.resource.ResourceException: Could not create conne
ction
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLo
calManagedConnection(LocalManagedConnectionFactory.java:277) [ironjacamar-jdbc-1
.0.9.Final.jar:1.0.9.Final]
Thanks in advance!
Deploy the oracle driver jar to jboss from the console. Its something like localhost:9990/console with credential test/test123
From the datasource option, check whether you can see your datasource java:jboss/hqiis over there or not. If not, try to create the datasource from the console instead of configuring through xml.
Also check the data source status from the jboss-cli:
a. From command prompt, enter into JBOSS_HOME\bin
b. Type connect YOUR_IP:YOUR_PORT (example 192.169.1.10:9999)
c. Type this to see whether your datasource is available or not:
/subsystem=datasources/data-source=hqiis:test-connection-in-pool
You should see a msg like below if you are having a configured datasource named hqiis
connection-in-pool
{
"outcome" => "success",
"result" => [true]
}
I'm using Jboss AS 7.1.1.final and I'm trying to add an oracle Datasource:
<datasource jndi-name="java:jboss/datasources/DefaultDS"
pool-name="DefaultDS"
enabled="true"
use-java-context="true">
<connection-url>jdbc:oracle:oci#TNS_NAME</connection-url>
<driver>oracle</driver>
<security>
<user-name>username</user-name>
<password>pwd</password>
</security>
</datasource>
And the driver:
<driver name="oracle" module="com.oracle.ojdbc">
<xa-datasource-class>oracle.jdbc.OracleDriver</xa-datasource-class>
</driver>
But when I start the server I get:
JBAS014775: New missing/unsatisfied dependencies:
service jboss.jdbc-driver.oracle (missing) dependents: [service jboss.data-source.java:jboss/datasources/DefaultDS]
I have a module under modules/com/oracle/ojdbc/main:
<module xmlns="urn:jboss:module:1.0" name="com.Oracle.ojdbc">
<resources>
<resource-root path="ojdbc6.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
and of course the jar is there.
Can someone please tell me what am I doing wrong here?
Add this to define driver: for xa datasource
<driver name="oracleDriver" module="com.oracle.ojdbc">
<driver-class>oracle.jdbc.OracleDriver</driver-class>
<xa-datasource-class>oracle.jdbc.xa.OracleXADataSource</xa-datasource-class>
</driver>
for non-xa-------
<driver name="oracleDriver" module="com.oracle.ojdbc">
<driver-class>oracle.jdbc.OracleDriver</driver-class>
</driver>
Got the answer:
In the drivers section, I defined the driver as sitting in module "com.oracle.ojdbc" but the module itself is actually defined with capital 'O' in 'Oracle' so it should be "com.Oracle.ojdbc"
Add this to define driver: for xa datasource
<driver name="oracleDriver" module="com.oracle.ojdbc">
<driver-class>oracle.jdbc.OracleDriver</driver-class>
<xa-datasource-class>oracle.jdbc.xa.OracleXADataSource
for non-xa-------
<driver name="oracleDriver" module="com.oracle.ojdbc">
<driver-class>oracle.jdbc.OracleDriver</driver-class>
</driver>
Path for the ojdbc jar in my case was : D:\ProgramFiles\JBoss6.4\modules\com\oracle\jdbc7\main where D:\ProgramFiles\JBoss6.4\ is the JBOSS HOME directory.
in the main folder, need to have following files.
ojdbc7.jar
module.xml
Entry for Module would look like below:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.oracle.jdbc7">
<properties>
<property name="jboss.api" value="unsupported"/>
</properties>
<resources>
<resource-root path="ojdbc7.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
You can define datasource from admin interface, find good tutorial below
http://middlewaremagic.com/jboss/?p=350