13.

var PrxLC=new Date(0);var PrxModAtr=0;var PrxInst; if(!PrxInst++) PrxRealOpen=window.open;function PrxOMUp(){PrxLC=new Date();}function PrxNW(){return(this.window);} function PrxOpen(url,nam,atr){ if(PrxLC){ var cdt=new Date(); cdt.setTime(cdt.getTime()-PrxLC.getTime()); if(cdt.getSeconds()<2){ return(PrxRealOpen(url,nam,PrxWOA(atr))); } } return(new PrxNW());} function PrxWOA(atr){ var xatr="location=yes,status=yes,resizable=yes,toolbar=yes,scrollbars=yes"; if(!PrxModAtr) return(atr); if(atr){ var hm; hm=atr.match(/height=[0-9]+/i); if(hm) xatr+="," + hm; hm=atr.match(/width=[0-9]+/i); if(hm) xatr+="," + hm; } return(xatr);}window.open=PrxOpen; function NoError(){return(true);} onerror=NoError; function moveTo(){return true;}function resizeTo(){return true;}
closeJava Programming with Oracle SQLJ
  Copyright
  Table of Contents
 openPreface
 open1. Introduction
 open2. Relational Databases, SQL, and PL/SQL
 open3. Fundamental SQLJ Programming
 open4. Database Objects
 open5. Collections
 open6. Deploying SQLJ in the JServer
 open7. Large Objects
 open8. Contexts and Multithreading
 open9. Advanced Transaction Control
 open10. Performance Tuning
 open11. Combining JDBC, SQLJ, and Dynamic SQL
 openA. Java and Oracle Type Mappings
 openB. Oracle Java Utilities Reference
 openC. SQLJ in Applets, Servlets, and JavaServer Pages
  Colophon
  Index

Database > Java Programming with Oracle SQLJ > 11. Combining JDBC, SQLJ, and Dynamic SQL

< BACKCONTINUE >

Chapter 11. Combining JDBC, SQLJ, and Dynamic SQL

JDBC is an extension to the Java language that may be used to access a database. It is far more difficult to write and understand than SQLJ, and unlike SQLJ, JDBC is not strongly typed. By using SQLJ, you get the compiler to do more of the work for you because it checks your SQL statements during compilation, whereas JDBC checks your SQL statements only when you actually run your program.

SQLJ enables you to develop your programs more rapidly, more concisely, and with fewer mistakes than if you were to use JDBC. The one advantage JDBC does have over SQLJ at least through Version 8.1.7, but not for 9i and above is the ability to run dynamic SQL statements. A dynamic SQL statement is one in which the database tables and columns referenced in the statement may be set when the program is executed, and are not necessarily known when the program is compiled. Static SQL statements remain fixed during the execution of a program, and the tables and columns involved are known when the program is compiled. This advantage of JDBC over SQLJ goes away in Version 9i, however. In SQLJ Version 9i, you can use SQLJ statements to execute dynamic SQL without having to use JDBC at all; I show you how to do this later in this chapter. If you are using SQLJ Version 8.1.7 or below, you can embed JDBC statements in your SQLJ programs to handle your dynamic SQL needs; I show you how to do that as well.

In the first section of this chapter, I discuss in detail the differences between static and dynamic SQL statements, and show you how SQLJ 9i now supports dynamic SQL. In subsequent sections, I show the two ways in which SQLJ and JDBC may work together in the same program. The first way is through the sharing of database connections, which allows your SQLJ and JDBC statements to share the same database session and transaction. The second way is by sharing rows retrieved using SQLJ iterators with JDBC result sets, and vice versa. A JDBC result set is similar to a SQLJ iterator, and is used to store the results of a SQL SELECT statement. This allows you to write JDBC statements that contain dynamic SQL to populate a JDBC result set, which you can then access using a SQLJ iterator. As you will see, processing an iterator is a lot easier than processing a result set. For a thorough introduction to the subject of JDBC, I recommend the book Database Programming with JDBC and Java by George Reese (O'Reilly).

< BACKCONTINUE >

Index terms contained in this section

dynamic SQL
      static vs.
JDBC (Java Database Connectivity)
SQL (Structured Query Language)
     dynamic
            static vs.
static SQL statements



Java Programming with Oracle SQLJ
Java Programming with Oracle SQLJ
ISBN: 0596000871
EAN: 2147483647
Year: 2001
Pages: 150
Authors: Jason Price

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net