DB2 version SQLJ access to Oracle Server

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.