How to Create a FairCom JDBC Project in IntelliJ IDEA
This document shows how to use IntelliJ IDEA to create a JDBC project that uses FairCom DB.
These procedures have been tested with:
Oracle Java version 8, 9, 11, 16, and OpenJDK 16.
IntelliJ IDEA 2021.1.
They are known to work with the JDBC API.
Overview
You need to include the <faircom>\drivers\sql.jdbc\ctreeJDBC.jar file to have access to the FairCom JDBC driver, so that Class.forName( "ctree.jdbc.ctreeDriver" ); can load the class.
Step-by-Step Instructions
Create a new project using the menu: File > New > Project, or select the New Project button from the welcome screen.
(The recent projects have been intentionally blurred in this image.)
Leave Java selected in the left pane, do not check any libraries or frameworks, and click Next.
Leave the Create project from template unchecked, and click Next.
Give the project a name and location, and click Finish.
If you are prompted that the directory does not exist, click Create.
In the Project window, expand your project name, and right-click on the blue src folder, select New > Java Class.
In the pop-up, give the class a valid name. You can set the class name to something similar to the project name.
Add the FairCom JDBC driver to the project with File > Project Structure.
Select Libraries in the left column.
In the center column, click + (New Project Library) and select Java.
Browse to the drivers/sql.jdbc/ directory and select ctreeJDBC.jar. Click OK.
Click OK to add that library to the only module.
Click OK to save those settings.
Now you can add your own code, or copy in the code from one of the tutorials provided in the drivers/sql.jdbc/tutorials/ directory. For example, if you use the code from drivers/sql.jdbc/tutorials/JDBC_Tutorial1.java, you will copy only the code between the first and last braces of the tutorial, and paste that in between the only braces of the class you just created. The result will look like this:
Note that IDEA automatically imported some classes. This was due to a configuration setting that you may, or may not, have set.
You will also note that Connection and Statement are unresolved. This is because we lack the proper imports for those:
Left-clicking on Connection will bring up the import dialog. Press Alt+Enter to select the java.sql.Connection class.
Repeat the previous step for Statement. Note that when you include the java.sql.Statement class, the import lines above will likely switch several lines into just java.sql.*. This feature can be controlled in the IDE configuration under Editor > Code Style > Java > Class count to use import with ‘*’.
Use Build > Build Project to ensure that every dependency has been met. The output from the build tab (at the bottom of the screen) should look similar to this:
The simplest way to run the program now is to click on the green arrow next to the class or next to main(). Each of them will bring up the same menu, with the first option being to run main(). Use that first option to run your program:
Running your program will result in the Run windows automatically opening. The output should look like this:
Note, you may need to click into the text area of the Run window and press Enter to finish running the program.
That’s it. Now you can modify this code to suit your needs.