Add JDBC provider in WebSphere

Home > Search
  by

Configuring WebSphere to handle the connection to a database is a multi-step process. This assumes you already have a working database, such as MySQL, MariaDB, Oracle, DB2, or SQL Server. First, you place the database JAR file on each node. Then you create the JDBC provider that uses the database JAR file. Next, you create a data source to use the JDBC driver.  Then, you configure the J2C alias (username, password). Then, apps can be configured to use the data source.

 

It is also helped to recognize that an app deployed to WebSphere can make a connection to a database without configuring the JDBC provider, data source, and J2C alias. As an example, the JAR to connect to the database could be placed in the apps /WEB-INF/lib directory, and then the username and password to connect to the database could be hard coded into the app or obtained from a properties file. The reason it usually makes sense to configure an app to make the connection to the database via WebSphere's JDBC provider, data source, and J2C alias is so that you have a single JAR on the system and a single place where the username and password are stored, which makes things easier to manage, especially when dealing with a large number of apps.

 


In ths example, the MySQL JDBC driver is downloaded, from https://dev.mysql.com/downloads/connector/j/. This will download a tar archive. Move the tar archive onto your WebSphere server (Linux in this example). You wouldn't place the JAR on the dmgr server. Instead, you place the JAR on each WebSphere server that has the JVMs. Decompress the gzip compress tar archive.

~]# gunzip mysql-<version>.tar.gz

 

Extract the tar archive.

~]# tar -xf mysql-<version>.tar

 

Copy the MySQL JAR into a directory where you will be storing your JDBC drivers (/opt/jdbc in this example).

~]# cp mysql-connector-java-version-bin.jar /opt/jdbc

 

In a clustered environment, repeat the above steps on the other servers in the cluster.

 

Add the JDBC driver to WebSphere.

  1. In the left panel of the WebSphere web console, expand Resources > JDBC.
  2. Select JDBC provider.
  3. In the scope drop-down selector, select a scope (cluster, node, server). Only applications that are in the same scope will be able to use the JDBC provider.
  4. Select New.
  5. At Step 1: Create new JDBC provider, select the appropriate database type.

Note: If the drop down does not contain the database you are using, select User-defined, and then provide the implementation class, name, and description. To determine the implementation class, you can view the contents of the JAR. In the JAR should be a references to the data source, such as org/mariadb/jdbc/MariaDbDataSource. In this scenario, the implementation class would be org.mariadb.jdbc.MariaDbDataSource

  1. At Step 2, enter the path to where the JAR is located on the WebSphere server and select Next.
  2. At step 3, select Finish
  3. Select Save.

The JDBC provider should now be displayed. Next, create the data source.

 


WSAdmin

The wsadmin.sh (Linux) or wsadmin.bat (Windows) command can also be used to create a data source. This usually only makes sense if there is some problem with the web console, or as part of a scripted process.

wsadmin> AdminTask.createJDBCProvider('[-scope Cell=myCell -databaseType DB2 -providerType "DB2 Universal JDBC Driver Provider"
 -implementationType "XA datasource" -name "DB2 Universal JDBC Driver Provider (XA)" 
-description "XA DB2 Universal JDBC 
Driver-compliant Provider. 
Datasources created under this provider support the use of XA to perform 2-phase commit processing. Use of driver
 type 2 on WAS z/OS is not supported for datasources created under this provider." -classpath
 ${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc.jar;${UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cu.jar;
${DB2UNIVERSAL_JDBC_DRIVER_PATH}/
db2jcc_license_cisuz.jar -nativePath ${DB2UNIVERSAL_JDBC_DRIVER_NATIVEPATH}]')

 

Use the following command to list the JDBC Providers.

# Jython
wsadmin> AdminTask.listJDBCProviders()

# Jacl
wsadmin> $AdminTask listJDBCProviders()

 

Use the following command to delete a JDBC Provider.

# Jython
wsadmin> AdminTask.deleteJDBCProvider('DB2 Universal JDBC Driver Provider (XA)
(cells/myCell|resources.xml#JDBCProvider_1180538152781)')

# Jacl
wsadmin> $AdminTask deleteJDBCProvider "DB2 Universal JDBC Driver Provider
 (XA)(cells/myCell|resources.xml#JDBCProvider_1180538152781)"

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments