JDBC (Java Database Connectivity) is a Java API to connect and execute the query with the database. It is a part of JavaSE (Java Standard Edition). JDBC API uses JDBC drivers to connect with the database. The JDBC driver converts the application code to the database language. This means that if the correct driver is installed, an application can be used with any supported database.
Install a JDBC Driver as a Module
JDBC drivers can be installed as a core module using the management CLI using the following steps.
1. Download the appropriate JDBC driver from your database vendor.
2. Start the JBoss EAP/WildFly server.
3. Launch the management CLI with--connect argument to connect to the running instance.
JDBC drivers can be installed as a core module using the management CLI using the following steps.
1. Download the appropriate JDBC driver from your database vendor.
2. Start the JBoss EAP/WildFly server.
3. Launch the management CLI with--connect argument to connect to the running instance.
$ EAP_HOME/bin/jboss-cli.sh --connect
|
And you will get the below cli
[standalone@localhost:9990 /] |
4. Use the module add management CLI command to add the new core module. Syntax :- module add --name=<MODULE_NAME> --resources=<PATH_TO_JDBC_JAR> --dependencies=<DEPENDENCIES>
[standalone@localhost:9990 /] module
add –name=com.mysql
--resources=/tmp/mysql-connector-java-5.1.47-bin.jar
--dependencies=javax.api,javax.transaction.api |
5. Now you can see the datasource module added into the EAP_HOME/modules.
$ ls EAP_HOME/modules/com/mysql/main/ module.xml mysql-connector-java-5.1.47-bin.jar |
6. We have added the mysql jar as a module in EAP_HOME/modules and now register the mysql JDBC driver.
Syntax :- /subsystem=datasources/jdbc-driver=<DRIVER_NAME>:add(driver-name=<DRIVER_NAME>,driver-module-name=<MODULE_NAME>,driver-xa-datasource-class-name=<XA_DATASOURCE_CLASS_NAME>, driver-class-name=<DRIVER_CLASS_NAME>)
Syntax :- /subsystem=datasources/jdbc-driver=<DRIVER_NAME>:add(driver-name=<DRIVER_NAME>,driver-module-name=<MODULE_NAME>,driver-xa-datasource-class-name=<XA_DATASOURCE_CLASS_NAME>, driver-class-name=<DRIVER_CLASS_NAME>)
[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, driver-class-name=com.mysql.jdbc.Driver) |
7. You can see the datasource module has been registered in standalone.xml into the “<driver>” section of datasources subsystem.
8. Now add the datasource connection.
Syntax :- /subsystem=datasources/data-source=<DATASOURCE_NAME>:add(jndi-name=java:/<JNDI_NAME>, driver-name=<DRIVER_NAME>, connection-url="jdbc:mysql://<DATABASE_SERVER_NAME>:<DB_PORT>/<DATABASE_NAME>", user-name=<DB_USER>, password=<DB_PASSWORD>)
9. And also the datasource connection has been added in standalone.xml into the “<datasource>” section of datasources subsystem.
<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> |
Syntax :- /subsystem=datasources/data-source=<DATASOURCE_NAME>:add(jndi-name=java:/<JNDI_NAME>, driver-name=<DRIVER_NAME>, connection-url="jdbc:mysql://<DATABASE_SERVER_NAME>:<DB_PORT>/<DATABASE_NAME>", user-name=<DB_USER>, password=<DB_PASSWORD>)
[standalone@localhost:9990 /] /subsystem=datasources/data-source=mysql_jndi:add(jndi-name=java:/mysql_jndi, driver-name=mysql, connection-url="jdbc:mysql://192.168.122.165:3306/JBTRAVEL", user-name=JBTRAVEL, password=JBTRAVEL) |
<datasource
jndi-name="java:/mysql_jndi" pool-name="mysql_jndi"> <connection-url>jdbc:mysql://192.168.122.165:3306/JBTRAVEL</connection-url> <driver>mysql</driver> <security> <user-name>JBTRAVEL</user-name> <password>JBTRAVEL</password> </security> </datasource> |
10. Now test the datasource connection.
Syntax :- /subsystem=datasources/data-source=<DATASOURCE_NAME>:test-connection-in-pool
Syntax :- /subsystem=datasources/data-source=<DATASOURCE_NAME>:test-connection-in-pool
[standalone@localhost:9990 /] /subsystem=datasources/data-source=mysql_jndi:test-connection-in-pool |
Comments
Post a Comment