HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML

"SQL Embedded in Java Part 1 Starting Out"
Vol 5, Issue 5, p.40


Listing 1:
import java.sql.SQLException; 
import sqlj.runtime.ref.DefaultContext; 
public class HiScotty { 
public static void main(String[] args) throws SQLException 
{ new oracle.jdbc.driver.OracleDriver(); 
(new DefaultContext("jdbc:oracle:oci8:@", "scott", "tiger", false)); 
String name = "SCOTT"; 
#sql { UPDATE emp SET sal = sal * 1.1 WHERE ename = :name }; 
#sql { COMMIT }; 
} } 
String[] emps = new String[] { "Scott", "Miller", "King" }; 
double[] raises = new double[] { 8.0, 4.0, 0.0 }; 
for (int i=0; i<emps.length; i++) 
#sql { UPDATE emp SET sal = sal * :(1.0 + raises[i] / 100.0) 
WHERE ename = :(emps[i].toUpperCase()) }; 
int j=0; double[] s = new double[emps.length]; 
while (j<emps.length) { 
#sql { SELECT sal INTO :(s[j]) FROM emp 
WHERE ename = :(emps[j++].toUpperCase()) }; } 


All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: info@sys-con.com

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.