JDBC drivers can be installed as a JAR deployment using either the management CLI or the management console. As long as the driver is JDBC 4-compliant, it will automatically be recognized and installed as a JDBC driver upon deployment.
1. Download the appropriate JDBC driver from your database vendor.
2. Start the JBoss EAP/WildFly server.
3. Now most of the drivers coming with JDBC 4-compliant, but in case If the JDBC driver JAR is not JDBC 4-compliant, it can be made deployable using the following steps.
i) Create a directory structure META-INF/services on your local system.
$ mkdir -p META-INF/services |
ii) Create a file inside META-INF/services/java.sql.Driver.
$ touch META-INF/services/java.sql.Driver |
iii) Add one line in the file to indicate the fully-qualified class name of the JDBC driver.
$ echo “com.mysql.jdbc.Driver” > META-INF/services/java.sql.Driver |
iv) Use the JAR command-line tool to add this new file to the JAR.
$ jar \-uf mysql-connector-java-5.1.47-bin.jar META-INF/services/java.sql.Driver |
v) Now this JAR is ready to deploy.
4. Deploy the JAR to JBoss EAP. There is two way to deployment – either you can direct copy the JAR file into the deployment directory where your standalone is running or you can do it from jboss console.
[standalone@localhost:9990 ]deploy /tmp/mysql-connector-java-5.1.47-bin.jar |
12:45:25,335 INFO
[org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2)
WFLYJCA0019: Stopped Driver service with driver-name = mysql 12:48:00,927 INFO [org.jboss.as.repository] (DeploymentScanner-threads - 1) WFLYDR0001: Content added at location /opt/wildfly-11.0.0.Final/standalone/data/content/63/e2cbc99a452e2696852918a30c5a8ade104ce1/content 12:48:00,939 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) WFLYSRV0027: Starting deployment of "mysql-connector-java-5.1.47-bin.jar" (runtime-name: "mysql-connector-java-5.1.47-bin.jar") 12:48:01,219 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) WFLYJCA0005: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1) 12:48:01,220 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) WFLYJCA0005: Deploying non-JDBC-compliant driver class com.mysql.fabric.jdbc.FabricMySQLDriver (version 5.1) 12:48:01,233 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) WFLYJCA0018: Started Driver service with driver-name = mysql-connector-java-5.1.47-bin.jar_com.mysql.jdbc.Driver_5_1 12:48:01,234 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) WFLYJCA0018: Started Driver service with driver-name = mysql-connector-java-5.1.47-bin.jar_com.mysql.fabric.jdbc.FabricMySQLDriver_5_1 12:48:01,359 INFO [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-2) ISPN000128: Infinispan version: Infinispan 'Chakra' 8.2.8.Final 12:48:01,565 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 62) WFLYCLINF0002: Started client-mappings cache from ejb container 12:48:01,617 INFO [org.jboss.as.server] (DeploymentScanner-threads - 1) WFLYSRV0010: Deployed "mysql-connector-java-5.1.47-bin.jar" (runtime-name : "mysql-connector-java-5.1.47-bin.jar") |
6. You can see “driver-name = mysql-connector-java-5.1.47-bin.jar_com.mysql.jdbc.Driver_5_1” in the EAP logs, that’s our JDBC driver.
12:48:01,233 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) WFLYJCA0018: Started Driver service with driver-name = mysql-connector-java-5.1.47-bin.jar_com.mysql.jdbc.Driver_5_1 |
7. We have deployed the mysql driver in EAP_HOME/standalone/deployments and 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>)
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-connector-java-5.1.47-bin.jar_com.mysql.jdbc.Driver_5_1, connection-url="jdbc:mysql://192.168.122.165:3306/JBTRAVEL", user-name=JBTRAVEL, password=JBTRAVEL) |
8. Now you can see the datasource connection added into the standalone.xml file.
<datasource
jndi-name="java:/mysql_jndi" pool-name="mysql_jndi"> <connection-url>jdbc:mysql://192.168.122.165:3306/JBTRAVEL</connection-url> <driver>mysql-connector-java-5.1.47-bin.jar_com.mysql.jdbc.Driver_5_1</driver> <security> <user-name>JBTRAVEL</user-name> <password>JBTRAVEL</password> </security> </datasource> |
9. 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 |
I truly appreciate the time and work you put into sharing your knowledge. I found this topic to be quite effective and beneficial to me. Thank you very much for sharing. Continue to blog.
ReplyDeleteData Engineering Services
Artificial Intelligence Solutions
Data Analytics Solutions
Data Modernization Solutions
I truly appreciate the time and work you put into sharing your knowledge. I found this topic to be quite effective and beneficial to me. Thank you very much for sharing. Continue to blog.
ReplyDeleteData Engineering Services
AI & ML Solutions
Data Analytics Services
Data Modernization Services
I appreciate you taking the time and effort to share your knowledge. This material proved to be really efficient and beneficial to me. Thank you very much for providing this information. Continue to write your blog.
ReplyDeleteData Engineering Services
Artificial Intelligence Solutions
Data Analytics Services
Data Modernization Solutions