SringSring

Tuesday, 8 September 2015

JDBC 2.0

Overview of JDBC 2.0 Features

Table 4-1 lists key areas of JDBC 2.0 functionality and points to where you can go in this manual for more information about Oracle support.
Table 4-1 Key Areas of JDBC 2.0 Functionality

Feature Comments and References 

update batching  

Also available previously as an Oracle extension. With release 8.1.6 and higher, under either JDK 1.2.x or JDK 1.1.x you can use either the standard update batching model or the Oracle model.
See "Update Batching" for information.  

result set enhancements (scrollable and updatable result sets)  

With release 8.1.6 and higher, this is also available under JDK 1.1.x as an Oracle extension.
See Chapter 12, "Result Set Enhancements" for information.  

fetch size / row prefetching  

With release 8.1.6 and higher, the JDBC 2.0 fetch size feature is also available under JDK 1.1.x as an Oracle extension.
Under either JDK 1.2.x or JDK 1.1.x, you can also use Oracle row prefetching, which is largely equivalent to the JDBC 2.0 fetch size feature but predates JDBC 2.0.
See "Fetch Size" and "Oracle Row Prefetching" for information.  

use of JNDI (Java Naming and Directory Interface) to specify and obtain database connections  

This requires data sources, which are part of the JDBC 2.0 Optional Package (JDBC 2.0 Standard Extension API) in the javax.sql package. With release 8.1.6 and higher this is available under either JDK 1.2.x or JDK 1.1.x.

connection pooling (framework for connection caching)  

This requires the JDBC 2.0 Optional Package (JDBC 2.0 Standard Extension API) in the javax.sql package. With release 8.1.6 and higher this is available under either JDK 1.2.x or 1.1.x.
See "Connection Pooling" for information.  

connection caching (sample Oracle implementation)  

This requires the JDBC 2.0 Optional Package (JDBC 2.0 Standard Extension API) in the javax.sql package. With release 8.1.6 and higher, this is available under either JDK 1.2.x or 1.1.x.
See "Connection Caching" for information.  

distributed transactions / XA functionality  

This requires the JDBC 2.0 Optional Package (JDBC 2.0 Standard Extension API) in the javax.sql package. With release 8.1.6 and higher,, this is available under either JDK 1.2.x or 1.1.x.
See Chapter 16, "Distributed Transactions" for information.  

miscellaneous getXXX() methods  

See "Other getXXX() Methods" for information about which getXXX() methods are Oracle extensions under JDK 1.2.x and 1.1.x, and about any differences in functionality with JDBC 2.0.  

miscellaneous setXXX() methods  

See "Other setXXX() Methods" for information about which setXXX() methods are Oracle extensions under JDK 1.2.x and 1.1.x, and about any differences in functionality with JDBC 2.0.  



1.Moving the Cursor in Scrollable Result Sets 
------------------------------------------------
In the JDBC 1.0 API, the only way to move the cursor was to call the method next . But in JDBC 2.0 API you have many other ways to move the cursor. The counterpart to the method next is the new method previous , which moves the cursor backward

2.Making Updates to Updatable Result Sets 
----------------------------------------
The new methods in JDBC 2.0 API, which JDBC 1.0 API doesnt have, for the ResultSet interface is: insert a new row into ResultSet object, delete an existing row from ResultSet object, or modify a column value in ResultSet object.

3.Updating, Inserting and Deleting a Result Set Programmatically
----------------------------------------------------------------
Using the JDBC 1.0 API, the update statemnet would look something like this:


stmt.executeUpdate("UPDATE COFFEES SET PRICE = 10.99" +
"WHERE COF_NAME = FRENCH_ROAST_DECAF");

The following code fragment shows another way to accomplish the update, this time using the JDBC 2.0 API:


uprs.last();
uprs.updateFloat("PRICE", 10.99);
uprs.updateRow();
(Here uprs is the ResultSet object)

Update operations in the JDBC 2.0 API affect column values in the row where the cursor is positioned, so in the first line the ResultSet uprs calls the method last to move its cursor to the last row . Once the cursor is on the last row, all of the update methods you call will operate on that row until you move the cursor to another row. The second line changes the value in the PRICE column to 10.99 by calling the method updateFloat. This method is used because the column value we want to update is a float in the Java programming language. To make the update take effect in the database and not just the result set, we must call the ResultSet methodupdateRow.

Similarly, to insert a row, instead of using executeUpdate(...), you should invoke the method moveToInsertRow, then set a value for each column in the row. You do this by calling the appropriate updateXXX method for each value and then call uprs.insertRow().

Now, to delete a row, say 4th row from a table, you call:
uprs.absolute(4);
uprs.deleteRow();
This will remove fourth row from ResultSet object and also from the database.

4. Using Statement Objects for Batch Updates
------------------------------------------------
In the JDBC 1.0 API, Statement objects submit updates to the database individually with the method executeUpdate. Multiple executeUpdate statements can be sent in the same transaction, but even though they are committed or rolled back as a unit, they are still processed individually. The interfaces derived from Statement, PreparedStatement and CallableStatement, have the same capabilities, using their own version of executeUpdate.

With the JDBC 2.0 API, Statement, PreparedStatement, and CallableStatement objects have the ability to maintain a list of commands that can be submitted together as a batch. They are created with an associated list, which is initially empty. You can add SQL commands to this list with the method addBatch, and you can empty the list with the method clearBatch. You send all of the commands in the list to the database with the method executeBatch.

5.Using SQL3 Datatypes 
-----------------------
The datatypes commonly referred to as SQL3 types are the new datatypes being adopted in the next version of the ANSI/ISO SQL standard. The JDBC 2.0 API provides interfaces that represent the mapping of these SQL3 datatypes into the Java programming language. With these new interfaces, you can work with SQL3 datatypes the same way you do other datatypes.



No comments:

Post a Comment