Connect Bridge – How to use the JDBC Driver in Java code

Matteo GiordaniTechnical Leave a Comment

To connect to a database in Java using JDBC, drivers for JDBC need to be installed. Installation is not as straightforward as the C# ODBC counterpart so this guide will show you how to add JDBC drivers to your Java project and tell your application to use them.


The JDBC driver is a .jar file that must be bundled into your Java application library. Java also requires that the driver in the library is called by name. This article will go into detail showing you how to do this exactly, as the driver name is not always the same as it’s named in your files.

How to find the driver name that Java is looking for

Navigate to where your driver, that you would like to use, is located. This guide will use one from Connect Bridge:

Navigate to where your driver

Navigate here via command prompt. This can easily be done by typing cmd into the navigation bar whilst in the folder and hit enter

Navigate here via command prompt

Now you should have cmd open to the folder structure that holds your driver .jar

open to the folder structure

You can now enter this command to list the names Java recognizes for the file:

jar tf *NAME OF YOUR DRIVER.jar* | findstr Driver
command to list the names Java

After clicking enter, you will see a list of results with possible driver names for that driver

list of results with possible driver names

Based on the results above, we can deduce that the name of our driver is

com.cnsconnect.mgw.jdbc.MgDriver

We can deduce this based on the typical naming conventions and by eliminating the unlikely classes such as MgDriver$1, MgDriver$KeepAliveTask as they either contain dollar signs suggesting inner classes or auxiliary tasks or have names suggesting other purposes like test.class and TrustedConnectionExample.class

Adding the driver to a Java project

Now that we have our name for the driver, we can add it to our project and point Java to it. In your IDE (Eclipse is used in this example) navigate to your project > right click it > click on properties

name for the driver
Once in properties, navigate to Java Build Path > then to Libraries
navigate to Java Build
Once in the Libraries tab, click on the Classpath item > then click on  Add External JARs...
 Add External JARs
Navigate to where your .jar file is and add it. 
Navigate to where your .jar

You will now see that the driver has been added to the project library

driver has been added
The driver is now ready to use within the code. In order to specify the Connect Bridge driver to Java, code like this can be used: 
The driver is now ready to use

And just like that, your Java application will now use the driver to communicate to your database. Theoretically speaking, if you followed this short guide and you were making use of our Connect Bridge middleware, you would at this point be ready to start programmatically accessing data from countless Microsoft products, Salesforce, Quickbooks, SAP and many, many more.

More on Software Integration using Java


About the Author

Matteo
By Matteo Giordani, Solution Architect at Connecting Software.

As a Solution Architect at Connecting Software, it's important to know all of the little intricacies of the tools that you use on a day to day basis. It helps me do what I do better and I thought, why not share some of these uncommon tidbits of information with all of you. If this ends up helping at least a single person, I reckon it was worth the writeup."

Leave a Reply

Your email address will not be published. Required fields are marked *

For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.