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
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.
Ant
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:
C:Usersrob>ant -version
Apache Ant(TM) version 1.10.1 compiled on February 2 2017
Let’s compile
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. -->
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. -->
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
BUILD SUCCESSFUL
Total time: 12 seconds
In the C:compilemysql-connector-java-5.1.44buildmysql-connector-java-5.1.44-SNAPSHOT directory we find a compiled mysql-connector-java-5.1.44-SNAPSHOT-bin.
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.
Rob is an Integration Consultant & WSO2 Trainer with more than twenty year experience. In addition to his work he is an active blogger working on a number of articles on the ‘Internet of Things’ and a WSO2 ‘Getting Started with …’ series (WSO2 tutorial) in which he talks about WSO2 components and their purpose especially aimed at non-technical readers. Rob is a WSO2 expert and official WSO2 trainer.
Our services to facilitate the digital transformation of your business
WSO2
Solutions by industry
Learnings
Our Technologies for your Digital Transformation
Search
What kind of content are you looking for?
We appreciate it
Care to share
Please select one of the social media platforms below to share this pages content with the world
Manage Cookie Consent
This website uses cookies. Information about data processing can be found in our privacy policy.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.