Product Documentation

Creating a JDBC Project in IntelliJ IDEA

Next Topic

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

  1. 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.)

  2. Leave Java selected in the left pane, do not check any libraries or frameworks, and click Next.

  3. Leave the Create project from template unchecked, and click Next.

  4. Give the project a name and location, and click Finish.

  5. If you are prompted that the directory does not exist, click Create.

  6. In the Project window, expand your project name, and right-click on the blue src folder, select New > Java Class.

  7. In the pop-up, give the class a valid name. You can set the class name to something similar to the project name.

  8. Add the FairCom JDBC driver to the project with File > Project Structure.

  9. Select Libraries in the left column.

  10. In the center column, click + (New Project Library) and select Java.

  11. Browse to the drivers/sql.jdbc/ directory and select ctreeJDBC.jar. Click OK.

  12. Click OK to add that library to the only module.

  13. Click OK to save those settings.

  14. 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.

  15. You will also note that Connection and Statement are unresolved. This is because we lack the proper imports for those:

  16. Left-clicking on Connection will bring up the import dialog. Press Alt+Enter to select the java.sql.Connection class.
  17. 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 ‘*’.
  18. 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:

  19. 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:

  20. 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.

TOCIndex