Today I saw a book about Oracle SQLJ and wanted to try it. But my ubuntu14 only installed the streamlined client of Oracle.
No SQLJ, so thought with Ibm-db2 's Sqlj, incredibly successful.
First, copy the Runtime12ee.jar Runtime12.jar Translator.jar into the corresponding directory from the Oracle server side
Mine is placed in $oracle_home/sqlj/lib, where the $oracle_home is the thin client installation directory
/opt/ora11g/instantclient_11_2/
Second, add the $oracle_home/sqlj/lib/* to the Classpath
Third, the use of SQLJ program conversion needs to add-compile=false-c-classpath= $ORACLE _home/sqlj/lib/* options
Iv. examples
/* EMP.SQLJ source program
Sqlj-compile=false-c-classpath= $ORACLE _home/sqlj/lib/* EMP.SQLJ
Javac Emp.java
Java EMP
*/
Import java.sql.SQLException; /* Import the required Java classes */
Import sqlj.runtime.*; Java Runtime Support
Import sqlj.runtime.ref.*;
Import oracle.sqlj.runtime.*; Oracle Extensions
#sql iterator Myiter (string empno, string ename);
Class EMP/* Main class */
/* Define iterator processing result set */
{
public static void Main (String args[])
{
try {
/* Connect to the Oracle database, where the Thin driver is used */
oracle.connect ("Jdbc:oracle:thin:@192.168.0.110:1521:orcl", "Scott", "Tiger");
EMP st = new EMP ();
st.runexample ();
} catch (SQLException e) {
System.err.println ("Error Running the example:" + E);
} finally {
try {
oracle.close ();
} catch (SQLException e) {}
}
}
void Runexample () throws SQLException {/* define Runexample function Get and process results */
Myiter iter; /* Declare an instance of the iterator class */
#sql iter = {select empno,ename from emp}; /* Execute the embedded SQL statement and return the result to iterator */
while (Iter.next ()) {
/* Loop through each record of the result and output */
System.out.print ("EMPNO =" + iter.empno () + "");
System.out.println ("ename =" + Iter.ename ());
}
}
}
Run:
$SQLJ-compile=false-c-classpath= $ORACLE _home/sqlj/lib/* EMP.SQLJ
$ Javac Emp.java
$ Java EMP
EMPNO = 7369 ename = SMITH
EMPNO = 7499 ename = ALLEN
EMPNO = 7521 ename = WARD
EMPNO = 7566 ename = JONES
EMPNO = 7654 ename = MARTIN
EMPNO = 7698 ename = BLAKE
EMPNO = 7782 ename = CLARK
EMPNO = 7788 ename = SCOTT
EMPNO = 7839 ename = KING
EMPNO = 7844 ename = TURNER
EMPNO = 7876 ename = ADAMS
EMPNO = 7900 ename = JAMES
EMPNO = 7902 ename = FORD
EMPNO = 7934 ename = MILLER
DB2 version SQLJ access to Oracle Server