File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes what is difference between JDBC1 and JDBC2 ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "what is difference between JDBC1 and JDBC2 ?" Watch "what is difference between JDBC1 and JDBC2 ?" New topic

what is difference between JDBC1 and JDBC2 ?

Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
what is difference between JDBC1 and JDBC2 ? I should download it seperately , or it is bundled with JDK ?

Jyothi Lature
Ranch Hand

Joined: Oct 31, 2001
Posts: 60
Hi Edward,

JDBC API is bundled with JDK. So, When you download the JDK, you will get JDBC as well.
To mention some of the major differences found between these two APIs are as follows:

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" +

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

uprs.updateFloat("PRICE", 10.99);
(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 method updateRow.

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:
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.

Jyothi<br />Sun Certified Java Programmer<br />Brainbench Certified for Javascript
Weerawit Maneepongsawat
Ranch Hand

Joined: Apr 11, 2002
Posts: 203
very good explanation..

Thank you.

Weerawit<br />SCJP 1.4, SCWCD 1.2, SCWCD 1.4, SCBCD 1.3, SCBCD 5.0, SCMAD 1.0, SCJA 1.0, SCDJWS, SCJD, SCEA, SCDJWS 1.5
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Just to add to Jyothi's explanation, the JDK includes support for JDBC 2 in terms of providing the interfaces that define the JDBC API. The implementations of these interfaces are provided by a JDBC driver. To be able to use JDBC 2 your version of Java and your JDBC driver must support JDBC 2. This support is very common these days so there's no good reason to use JDBC 1 for new development. The latest version JDBC is JDBC 3 which adds additional support for things like connection pooling. Take a look at the javax.sql package or Google for JDBC 3 for more info.

I agree. Here's the link:
subject: what is difference between JDBC1 and JDBC2 ?
It's not a secret anymore!