Step-by-Step Instructions for Configuring Oracle SQLj in JBuilder 7

By: Christopher Moeller

Abstract: Getting started with SQLj compilation in JBuilder 7

Configuring Oracle SQLj in JBuilder 7


* Configuring JBuilder 7 for Oracle SQLj:

1. Choose: Tools | Configure Libraries | New... | enter "SQLj" for the "Name:" | leave the "Location" to "User Home" | Add... | navigate to the SQLj/lib directory and select the following two JARs:

runtime12.jar
translator.jar

Note: There may be several JAR files for each runtime. It is important to only add one runtime JAR. The "runtime12.jar" is used in the example, but if you wished to use the "runtime11.jar," you could select that JAR instead.

2. Choose: Tools | Configure Libraries | New... | enter "Oracle Driver" for the "Name:" | leave the "Location" to "User Home" | Add... | navigate to the location of the driver and select it (e.g. <Oracle Driver>/lib/classes12.jar).

Note: We distinguish the database driver from the SQLj libraries because it may be convienent in other cases to just have access to the database driver without the supporting SQLj JARs.

3. Choose: Tools | Enterprise Setup | SQLj | Oracle | click on the ellipsis button for the SQLj executable | use the dialog to navigate to the SQLj executable and select it. It should be located in SQLj/bin/sqlj.exe.

4. Choose: Tools | Enterprise Setup | SQLj | Oracle | and verify that your SQLj library (from step 1) is added to the "Library" listbox and click OK.

 

* Configuring project for SQLj (Oracle):

1. File | New Project | Finish

2. Right-click the .jpx file and choose "Add Files/Packages" | type "TestSQLj.sqlj" in the File Name field | OK | you will then receive a message indicating "The selected file does not exist. Do you wish to create it?" | OK.

3. In the Project Pane, right-click on "TestSQLj.sqlj" so that it opens in the Editor. Next paste in the following SQLj code:

 

import oracle.sqlj.runtime.Oracle;
import java.sql.SQLException;
import java.sql.Date;

// TestSQLj connects to the database and prints the date
public class TestSQLj
{

public static void main(String [] args)
{

java.sql.Date today;

try
{

// connect to the database
Oracle.connect( "jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger" );
// get the current date from the database
#sql { SELECT sysdate INTO :today FROM dual };
// display message
System.out.println("The date is " + today);

}

catch ( SQLException e ) { e.printStackTrace(); }
finally
{

try { Oracle.close(); }
catch ( SQLException e ) { e.printStackTrace(); }

}

}

}

 

4. File | Save All.

5. Choose: Project | Project Properties | Paths | Required Libraries | and add the "SQLj" library.

6. Choose: Project | Project Properties | Paths | Required Libraries | and add the "Oracle driver" library to the project.

7. Choose: Project | Project Properties | Build | SQLj | and select "Oracle" from the combobox.

8. In the Project Pane, right-click "TestSQLj.sqlj" and choose Make-- the class should compile successfully.


Server Response from: ETNASC04