Product Documentation

FairCom JDBC

Previous Topic

Next Topic

Command-Line Compile - Windows

This section explains the steps to compile and run the JDBC SQL tutorials from the Microsoft Windows command prompt.

If the FairCom Database Engine is not already running on your machine, start the server. See Starting the FairCom Database Engine.

Environment Variables

Although the installations of your JDK and FairCom SQL most likely have already set these environment variables, we will review them here. Execute the "set" command from your command-line and review your current settings.

PATH: Be sure that your PATH is set to include the path to your JDK. Setting the environment variable to your Oracle JDK might look something like this, although referencing the proper JDK on your machine:

set JDKDIR="C:\Program Files\Java\jdk1.7.0_07"

set PATH=%PATH%;%JDKDIR%\bin;%JDKDIR%\jre\bin;

CLASSPATH: Be sure that your CLASSPATH is set for your JDK and for the FairCom SQL JDBC Driver, as follows:

  1. Setting the CLASSPATH to contain the Oracle JRE runtime JAR file on your machine might look something like this, of course, referencing the proper JDK on your machine:

    set CLASSPATH="C:\Program Files\Java\jdk1.7.0_07"\jre\lib\rt.jar;

  2. Adding the c-treeEDGE SQL JDK JAR file and the proper “tutorials” folder to the Setting the environment variable for your FairCom DB SQL JDK CLASSPATH might look something like this, of course, referencing your c-treeEDGE installation directory.

    set CLASSPATH=%CLASSPATH%;C:\FairCom\V*\win32\lib\sql.jdbc\ctreeJDBC.jar;<FairCom-Folder>\tools\guitools.java\lib\ctreeJDBC.jar;<FairCom-Folder>\drivers\sql.jdbc\tutorials

    (You will need to adjust the path based on your installation.)

Compiling the Sample Code

To help you compile these tutorials you will find a batch file, drivers\sql.jdbc\tutorials\cmdline\BuildTutorials.bat, which automatically builds and then executes the tutorials in the tutorials directory. If you use this batch file you will find all the sql.jdbc tutorials compiled (with debugging information) in the drivers\sql.jdbc\tutorials directory.

To compile the tutorials without using the batch file, execute the following from the command line:

javac JDBC_Tutorial1.java

javac JDBC_Tutorial2.java

javac JDBC_Tutorial3.java

javac JDBC_Tutorial4.java

To execute the tutorials without using the batch file, run them as follows:

java JDBC_Tutorial1

java JDBC_Tutorial2

java JDBC_Tutorial3

java JDBC_Tutorial4

To fully observe JDBC in action, you can single-step through the code with a debugger (jdb) as follows:

jdb JDBC_Tutorial1

jdb JDBC_Tutorial2

jdb JDBC_Tutorial3

jdb JDBC_Tutorial4

Output

The output from the first tutorial project should appear similar to the following:

INIT

Logon to server...

DEFINE

Open table...

Add fields...

Create table...

MANAGE

Delete records...

Add records...

Display records...

1000 Bryan Williams

1001 Michael Jordan

1002 Joshua Brown

1003 Keyon Dooling

DONE

Close table...

Logout...

Press <ENTER> key to exit . . .

Troubleshooting

The examples below illustrate some of the errors that occur when these environment variables are not set properly.

Note: You may need to adjust the path to match your installation.

SQL Exception: 26003 - Connection refused: connect

The most common cause of this error tis that the FairCom Database Engine not running. Remember that the c-tree evaluation license times out after 3 hours, so the server might have exited and needs to be re-started. See Starting the FairCom Database Engine.

JDK not found! Please set environment for the Java JDK.

In this example we do not have the JDKDIR and PATH environment variable set properly, so it cannot find the Java JDK

<FairCom-Folder>\drivers\sql.jdbc\tutorials\cmdline>BuildTutorials.bat

'javac' is not recognized as an internal or external command, operable program or batch file.

In this example we do not have the Java environment variables set properly in our PATH.

<FairCom-Folder>\drivers\sql.jdbc\tutorials>javac JDBC_Tutorial1.java

INIT
Exception: ctree.jdbc.ctreeDriver
*** Execution aborted ***
Press <ENTER> key to exit...

In this example we do not have the CLASSPATH pointing to the FairCom SQL JDBC Driver directory.

<FairCom-Folder>\drivers\sql.jdbc\tutorials>java JDBC_Tutorial1

Error: Could not find or load main class JDBC_Tutorial1.class

In this example we attempt to execute a tutorial with the .class extension. Simply call the sample without this extension. Another source of this error is leaving the “drivers\sql.jdbc\tutorials” folder out of the CLASSPATH.

<FairCom-Folder>\drivers\sql.jdbc\tutorials>java JDBC_Tutorial1.class

TOCIndex