In this post, we are going to see how to upgrade the JDBC driver in WebLogic 12c and WebLogic 11g versions.
We are going to take mysql as our database for this example, but the same process applies to the Oracle as well.
The Context
If you are here, I can presume that you must be aware of how application servers communicate to the Database. Yes. The answer is JDBC and Application servers use various JDBC drivers to connect to different databases.
For Weblogic to connect to the MySQL, Weblogic must be having the MySQL JDBC driver. so does for Oracle and other Relational Database management Systems.
The JDBC driver names would vary or change based upon the Database product we are using
For Oracle Database the JDBC driver name would be ojdbc6.jar (or) ojdbc7.jar
wherein the case of MySQL the file name would be something like mysql-connector-<version-info>.jar
In general, Weblogic comes with these driver jar files, but they often get outdated when their time comes. Some companies and infrastructures choose to change their JDBC version for performance reasons as well. But it would mostly be accompanied by the Database product (or) version upgrade.
Now having this information clear. Let us find where weblogic keeps these JDBC related drivers by default and learn how to upgrade them for both versions ( Weblogic 11g and 12c)
Steps to Upgrade JDBC driver in Weblogic
Though the Process is more similar for both Weblogic11g and 12c there is few minor differences like the PATH and the FILE.
So we have given separate instructions for both versions, to keep things isolated and for better understanding. Hope this makes sense.
Let us go.
Weblogic 12c
Weblogic 12c directory structure is slightly different than the weblogic 11g
For weblogic 12c, The JDBC drivers (jar files) can be found in $ORACLE_HOME/oracle_common/modules
In my case: The ORACLE HOME is /apps/oracle-weblogic/wls12213
which is apparently my MW_HOME as well. Confusing?
In a fully featured Fusion Middleware installation setup, There would be many Oracle products installed under the same MW_HOME. In such cases there would be various ORACLE_HOMES might be present like $MW_HOME/weblogic12c, $MW_HOME/OracleHTTPServer
But, When it comes to only Weblogic installation and not full FMW setup. The ORACLE_HOME and MW_HOME would mostly be the same.
Since I have only Weblogic installed. I can refer to my MW_HOME here to get to oracle common directory
In fact, there is another exclusive variable like ORACLE_COMMON_HOME to avoid confusion. Refer the following post for more information on these homes.
To know more about all these HOME directories and how to find them and differentiate them easily. refer to this article.
Having said that, MW_HOME and ORACLE_HOME are the same in my case. The listing for oracle_common directory would look like this.
Once you found the directory where the JDBC driver files are present now it is the time to replace the JAR files with your desired version.
CAUTION: Having one or more version of same JAR file would create a Class Casting Exception so it is recommended to take a backup of the old JAR files some where and REPLACE with the new JAR file.
For this post, we are taking mysql as our Database but you can refer this for Oracle Database as well.
To upgrade the JDBC driver in weblogic you need to do two set of actions. The First one is Replace the existing JDBC driver and the second one is updating the Classpath
Step1: Replace the JDBC Driver
- Take a backup of the Existing JAR file in the
$ORACLE_HOME/oracle_common/modules
to somewhere in the file system ( NOT ON THE SAME DIRECTORY) - Download the latest mysql JDBC driver from here
- The Downloaded driver would mostly come in the Zipped format or as tarball. So un compress it to find the JAR file
- Take the JAR file and Just place it in the same directory
$ORACLE_HOME/oracle_common/modules
Step2: Update the Classpath
There are two options while updating the classpath, based on the scope of your change. Either a Single Domain (or) across all domains.
To Apply the Changes Across All the Domains
If you want the latest JDBC driver to be picked up across all the domains in the server. Perform the following steps
- Go to
$ORACLE_HOME/oracle_common/common/bin
- Take a backup of
commExtEnv.sh
and open the file in VI - Find the
WEBLOGIC_CLASSPATH
variable declaration - Append the new Fully Qualified Latest JDBC driver JAR file to the
WEBLOGIC_CLASSPATH
variable. Append the following line at the end of the WEBLOGIC_CLASSPATH:$MW_HOME/oracle_common/modules/mysql-connector-java-8.0.13.jar
Diff command output of the file before(RED) and after the change(GREEN)
Note*: If you have other Custom Client JAR files added into this variable already. You should prepend the JDBC driver JAR. (Add at the start of the line)
To Apply the Changes For a Single Domain
- Go to $DOMAIN_HOME/bin
- Open setDomainEnv.sh script
- Find the variable declaration
PRE_CLASSPATH
- Prepend (or) Append the Fully Qualified JAR file location to the
PRE_CLASSPATH
PRE_CLASSPATH=$PRE_CLASSPATH:$MW_HOME/oracle_common/modules/mysql-connector-java-8.0.13.jar
Weblogic 11g
As we stated earlier, Weblogic 11g directory structure is different than weblogic 12c.
Having said that. Finding the location of JDBC drivers is comparatively easy, cause there is no ORACLE_HOME and MW_HOME confusion here.
Just go to your MW_HOME which is mostly one level above to WL_HOME.
WL_HOME is the directory where your server
and common
directories would reside. If you are still confused about the HOME directories, You can refer to this article we have recommended earlier.
Step1: Replace the JDBC Driver
- Take a backup of the Existing JAR file in the
$MW_HOME/wlserver/server/lib
to somewhere in the file system ( NOT ON THE SAME DIRECTORY) - Download the latest mysql JDBC driver from here
- The Downloaded driver would mostly come in the Zipped format or as tarball. So un compress it to find the JAR file
- Take the JAR file and Just place it in the same directory
$MW_HOME/wlserver/server/lib
Step2: Update the Classpath
There are two options while updating the classpath, based on the scope of your change. Either a Single Domain (or) across all domains.
To Apply the Changes Across All the Domains
If you want the latest JDBC driver to be picked up across all the domains in the server. Perform the following steps
- Go to $MW_HOME/wlserver/common/bin
- Take a backup of
commEnv.sh
and open the file in VI - Find the
WEBLOGIC_CLASSPATH
variable declaration - Append the new Fully Qualified Latest JDBC driver JAR file to the
WEBLOGIC_CLASSPATH
variable. Append the following line at the end of the WEBLOGIC_CLASSPATH:$MW_HOME/wlserver/server/lib/mysql-connector-java-8.0.13.jar
Diff command output of the file before(RED) and after the change(GREEN)
Note*: If you have other Custom Client JAR files added into this variable already. You should prepend the JDBC driver JAR. (Add at the start of the line)
To Apply the Changes For a Single Domain
- Go to $DOMAIN_HOME/bin
- Open setDomainEnv.sh script
- Find the variable declaration
PRE_CLASSPATH
- Prepend (or) Append the Fully Qualified JAR file location to the
PRE_CLASSPATH
PRE_CLASSPATH=$PRE_CLASSPATH:
$MW_HOME/wlserver/server/lib/mysql-connector-java-8.0.13.jar
Conclusion
I know there are other options to place the JAR file like, $DOMAIN_HOME/lib
directory, which I have not covered intentionally. Cause it will create confusion and not the recommended approach for this JDBC driver upgrade case. In case you have any questions or face any issues. feel free to ask in the comments section. I will reply/help as soon as possible.
If you find this helpful Leave a rating [ratings]
As usual. Hope this helps too.
Signing off for now.
Sarav AK
Follow me on Linkedin My Profile Follow DevopsJunction onFacebook orTwitter For more practical videos and tutorials. Subscribe to our channel
Signup for Exclusive "Subscriber-only" Content