Note: | To build and run SQLJ programs with the IBM Java Development Kit for
UNIX, OS/2, and Windows 32-bit operating systems, you must turn off the
just-in-time compiler of the JDK with the following command for your operating
system:
|
The build file, bldsqlj, contains the commands to build an SQLJ applet or application. On UNIX this is a script file. On OS/2, it is the command file, bldsqlj.cmd, and on Windows, it is the batch file, bldsqlj.bat. The contents of the command and batch files are the same, and this version is presented first, followed by the UNIX script file. The applet and application building sections that follow will refer back to these build files.
Note: | The SQLJ translator shipped with DB2 compiles the translated .java files into .class files. Therefore, the build files in this section do not use the java compiler. |
In the following build file for OS/2 and Windows 32-bit operating systems, the first parameter, %1, specifies the name of your source file. The second parameter, %2, specifies the name of the database to which you want to connect. The third parameter, %3, specifies the user ID for the database, and %4 specifies the password. Only the first parameter, the source file name, is required. Database name, user ID, and password are optional. If no database name is supplied, the program uses the default sample database.
@echo off rem bldsqlj -- OS/2 and Windows 32-bit operating systems rem Builds a Java embedded SQL (SQLJ) program. rem Usage: bldsqlj prog_name [ db_name [ userid password ]] if "%1" == "" goto error rem Translate and compile the SQLJ source file rem and bind the package to the database. if "%2" == "" goto case1 if "%3" == "" goto case2 if "%4" == "" goto error goto case3 :case1 sqlj %1.sqlj db2profc -url=jdbc:db2:sample -prepoptions="package using %1" %1_SJProfile0 goto continue :case2 sqlj -url=jdbc:db2:%2 %1.sqlj db2profc -url=jdbc:db2:%2 -prepoptions="package using %1" %1_SJProfile0 goto continue :case3 sqlj -url=jdbc:db2:%2 -user=%3 -password=%4 %1.sqlj db2profc -url=jdbc:db2:%2 -user=%3 -password=%4 -prepoptions="package using %1" %1_SJProfile0 goto continue :continue goto exit :error echo Usage: bldsqlj prog_name [ db_name [ userid password ]] :exit @echo on
Translator and Precompile Options for bldsqlj |
---|
|
In the following UNIX script file, the first parameter, $1, specifies the name of your source file. The second parameter, $2, specifies the name of the database to which you want to connect. The third parameter, $3, specifies the user ID for the database, and $4 specifies the password. Only the first parameter, the source file name, is required. Database name, user ID, and password are optional. If no database name is supplied, the program uses the default sample database.
#! /bin/ksh # bldsqlj script file -- UNIX platforms # Builds a Java embedded SQL (SQLJ) sample # Usage: bldsqlj <prog_name> [ <db_name> [ <userid> <password> ]] # Translate and compile the SQLJ source file # and bind the package to the database. if (($# < 2)) then sqlj $1.sqlj db2profc -url=jdbc:db2:sample -prepoptions="package using $1" $1_SJProfile0 elif (($# < 3)) then sqlj -url=jdbc:db2:$2 $1.sqlj db2profc -url=jdbc:db2:$2 -prepoptions="package using $1" $1_SJProfile0 else sqlj -url=jdbc:db2:$2 -user=$3 -password=$4 $1.sqlj db2profc -url=jdbc:db2:$2 -user=$3 -password=$4 -prepoptions="package using $1" $1_SJProfile0 fi
Translator and Precompile Options for bldsqlj |
---|
|
Applt demonstrates an SQLJ applet that accesses a DB2 database.
To build this applet with the build file, bldsqlj, and then run it:
db2jstrt 6789
bldsqlj Applt [ <db_name> [ <userid> <password> ]]
where the optional parameter <db_name> allows you to access another database instead of the default sample database. The optional parameters <userid>, and <password> are needed if the database you are accessing is on a different instance, such as if you are accessing a server from a remote client machine.
Applt.html, Applt.class, Applt_Cursor1.class, Applt_Cursor2.class, Applt_SJProfileKeys.class, Applt_SJProfile0.ser
As an alternative to steps (1), (5) and (7), you can use the applet viewer that comes with the Java Development Kit by entering the following command in the working directory of your client machine:
appletviewer Applt.html
You can also use the Java makefile to build this program.
App demonstrates an SQLJ application that accesses a DB2 database.
To build this application with the build file, bldsqlj, enter this command:
bldsqlj App [ <db_name> [ <userid> <password> ]]
where the optional parameter <db_name> allows you to access another database instead of the default sample database. The optional parameters <userid>, and <password> are needed if the database you are accessing is on a different instance, such as if you are accessing a server from a remote client machine.
Run the Java interpreter on the application with this command:
java App
You can also use the Java makefile to build this program.
Stclient is the client program that calls the SQLJ stored procedure class, Stserver , using the JDBC Application driver. Before building and running this client application, build the stored procedure class on the server. See "Stored Procedures".
To build this client program with the build file bldsqlj, enter this command:
bldsqlj Stclient [ <db_name> [ <userid> <password> ]]
where the optional parameter <db_name> allows you to access another database instead of the default sample database. The optional parameters <userid>, and <password> are needed if the database you are accessing is on a different instance, such as if you are accessing a server from a remote client machine.
Run the Java interpreter on the client application with this command:
java Stclient
You can also use the Java makefile to build this program.
UDFclie is the client program that calls the user-defined functions implemented in the server program, UDFsrv , using the JDBC application driver. Before building and running this client application, build the UDFsrv program on the server. See "User-Defined Functions (UDFs)".
To build this SQLJ client program with the build file, bldsqlj, enter this command:
bldsqlj UDFclie [ <db_name> [ <userid> <password> ]]
where the optional parameter <db_name> allows you to access another database instead of the default sample database. The optional parameters <userid>, and <password> are needed if the database you are accessing is on a different instance, such as if you are accessing a server from a remote client machine.
Run the Java interpreter on client application with this command:
java UDFclie
You can also use the Java makefile to build this program.
The build file, bldsqljs, contains the commands to build an SQLJ stored procedure. On UNIX this is a script file. On OS/2, it is the command file, bldsqljs.cmd, and on Windows, it is a batch file, bldsqljs.bat. The contents of the command and batch files are the same, and this version is presented first, followed by the UNIX script file.
In the following build file for OS/2 and Windows 32-bit operating systems, the first parameter, %1, specifies the name of your source file. The second parameter, %2, specifies the name of the database to which you want to connect. Since the stored procedure must be built on the same instance where the database resides, there are no parameters for user ID and password.
Only the first parameter, the source file name, is required. If no database name is supplied, the program uses the default sample database.
@echo off rem bldsqljs -- OS/2 and Windows 32-bit operating systems rem Builds a Java embedded SQL (SQLJ) stored procedure rem Usage: bldsqljs prog_name [ db_name ] if "%1" == "" goto error rem Translate and compile the SQLJ source file rem and bind the package to the database. if "%2" == "" goto case1 goto case2 :case1 sqlj %1.sqlj db2profc -url=jdbc:db2:sample -prepoptions="package using %1" %1_SJProfile0 goto continue :case2 sqlj -url=jdbc:db2:%2 %1.sqlj db2profc -url=jdbc:db2:%2 -prepoptions="package using %1" %1_SJProfile0 :continue rem Copy the *.class and *.ser files to the 'function' directory. copy %1*.class "%DB2PATH%\function" copy %1*.ser "%DB2PATH%\function" goto exit :error echo Usage: bldsqljs prog_name [ db_name ] :exit @echo on
Translator and Precompile Options for bldsqljs |
---|
|
In the following UNIX script file, the first parameter, $1, specifies the name of your source file. The second parameter, $2, specifies the name of the database to which you want to connect. Since the stored procedure must be built on the same instance where the database resides, there are no parameters for user ID and password.
Only the first parameter, the source file name, is required. If no database name is supplied, the program uses the default sample database.
#! /bin/ksh # bldsqljs script file -- UNIX platforms # Builds a Java embedded SQL (SQLJ) stored procedure # Usage: bldsqljs <prog_name> [ <db_name> ] # Set DB2PATH to where DB2 will be accessed. # The default is the standard instance path. DB2PATH=$HOME/sqllib # Translate and compile the SQLJ source file # and bind the package to the database. if (($# < 2)) then sqlj $1.sqlj db2profc -url=jdbc:db2:sample -prepoptions="package using $1" $1_SJProfile0 else sqlj -url=jdbc:db2:$2 $1.sqlj db2profc -url=jdbc:db2:$2 -prepoptions="package using $1" $1_SJProfile0 fi # Copy the *.class and *.ser files to the 'function' directory. rm -f $DB2PATH/function/$1*.class rm -f $DB2PATH/function/$1*.ser cp $1*.class $DB2PATH/function cp $1*.ser $DB2PATH/function
Translator and Precompile Options for bldsqljs |
---|
|
Stserver demonstrates PARAMETER STYLE JAVA stored procedures using the JDBC application driver to access a DB2 database. Stored procedures are compiled and stored on a server. When called by a client application, they access the server database and return information to the client application.
To build this stored procedure class with the build file, bldsqljs:
bldsqljs Stserver [ <db_name> ]
where the optional parameter <db_name> allows you to access another database instead of the default sample database.
db2 connect to sample
If the stored procedures were previously cataloged, you can drop them with this command:
db2 -td@ -vf Stdrop.db2
Then catalog them with this command:
db2 -td@ -vf Stcreate.db2
You can also use the Java makefile to build this program.