In many cases, making a connection to a database in WSO2 is as simple as downloading a connector.
So, where can you find these connectors? In this blog I will explain you how to compile your JDBC connector to connect to a database in WSO2.
Let’s look at the list of databases that are typically supported by WSO2. The dbscripts directory shows the scripts where we typically find the regular RDBMS’. In other products, like DSS there is also support for NoSQL databases like Cassandra and MongoDB
|Database name||Version(s)*||URL Drivers / Remarks|
|Derby||10.7.1.||derby.jar, derbyclient.jar, and derbynet.jar from
the <DERBY_HOME>/lib/ directory to the <PRODUCT_HOME>/repository/components/
|MariaDB||10.0, 10.0.20 10.1||https://dev.mysql.com/downloads/connector
|MySQL||5.5, 5,6, 5,7||https://dev.mysql.com/downloads/connector/j/
|Oracle||10.2, 11.2, 12.1, 12c||http://www.oracle.com/technetwork/database
|PostgreSQL||8.4, 9.1, 9.3, 9.4, 9.5,9.5.3||https://jdbc.postgresql.org/|
|SQL Server||2005, 2008, 2012, 2014||https://docs.microsoft.com/en-us/sql/connect/sql-connection-libraries#anchor-20-drivers-relational-access|
|MongoDB||Only as a data source in DSS|
For specific sub-versions of the DBMS see the compatibility matrix. Other databases / versions might be supported when there is a JDBC connection and the database is a RDBMS. Furthermore, the NoSQL databases are supported as data sources mostly, not so much as the purpose of user or registry database.
Not in the list
If your database is not in the list but it is a RDBMS database with a JDBC connector available, it might work. Google for any information on your database and WSO2.
You would probably need to adapt the sql scripts in the dbscripts directory.
Compile your JDBC connector
When you download the MySQL connector you will find a zip file with the compiled mysql-connector jar file in the zip. However, it is quite simple to compile it yourself.
For those of you not familiar with compiling this kind of jar files, this is done with Ant. When we inspect the src directory we find a number of subdirectories. For instance, in srccommysqljdbc we find a large number of java files that make the actual connection to the database.
It would go too far to look deeper into these files so we will leave them and just do a simple compilation.
Ant or Maven?
You might think you need Maven for this purpose. But Maven uses a POM,xml file whereas Ant uses a build.xml. As you can see in the directory overview, there is just a build.xml file
We need to use ANT, let’s just download it.
If you do not have Ant on your computer, download and install it. If you have installed Ant and type ant -version, you will get a response like this on windows:
Apache Ant(TM) version 1.10.1 compiled on February 2 2017
Compiling the jar is as simple as typing in ant. However, we need both JDK5 and JDK8 for compilation we need to add the right parameters, either as commands or in the build file.
This snippet in the build file shows the dependencies.
<!-- The following properties are needed for finding JDK5 and JDK8 needed for compile and can be passed on the command line to ant via -D switches. -->
<property name="com.mysql.jdbc.jdk5" value=" C:Program FilesJavajdk1.5.0_22" />
<property name="com.mysql.jdbc.jdk8" value=" C:Program FilesJavajdk1.8.0_121”/>
Junit and Hibernate
But we are not out of the woods yet. We also need Junit jar files as well as hibernate jars. Where do I find all this knowledge? Well, partly it is in the return from the ant command. Some googling gets you to the documentation from MySQL with regards to compilation.
C:UsersrobDownloadsmysql-connector-java-5.1.44build.xml:247: Hibernate libraries, required for build tasks, must be in the directory './src/lib/hibernate4'.
We copy the Junit files from https://github.com/junit-team/junit/wiki/Download-and-Install and put them in a separate directory that we will link to from within the build file.
Another set of files we need are the jar files from the Hibernate ORM 4.1 or 4.2 Final release bundle available as a zip from http://sourceforge.net/projects/hibernate/files/hibernate4/. The jar files in the zip you download (in lib/required) need to go in a subdirectory hibernate4 in the separate directory.
Let’s say the directory is called /extralibs. The hibernate jars go in /extralibs/hibernate4. The Junit files go directly to /extralib. I am using Windows so the slashes tilt to right.
<!-- The following property allows to point the location of third-party libraries we don't distribute. Default value points to src/lib so user could either put these jars there or pass different location via ant -D switch. -->
<property name="com.mysql.jdbc.extra.libs" value="C:compileextralibs" />
We now have everything in place and we can start a new compilation. After starting ant and a quick compile we have a new build.
[jar] Building jar: C:compilemysql-connector-java-5.1.44buildmysql-connector-java-5.1.44-SNAPSHOTmysql-connector-java-5.1.44-SNAPSHOT-bin.jar
Total time: 12 seconds
C:compilemysql-connector-java-5.1.44buildmysql-connector-java-5.1.44-SNAPSHOT directory we find a compiled
The file size is roughly the same, a difference of a couple of bytes which could be because of the environment.
So, there you have your own compiled JDBC Jar file.
If you have any questions about this blogpost contact us via the comments section of this blog. View also our WSO2 Tutorials, webinars or white papers for more technical information. Need support? We do deliver WSO2 Product Support, WSO2 Development Support, WSO2 Operational Support and WSO2 Training Programs.