• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
  • salvin francis
  • Piet Souris

what is difference between JDBC1 and JDBC2 ?

Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is difference between JDBC1 and JDBC2 ? I should download it seperately , or it is bundled with JDK ?

Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
very good explanation..

Thank you.
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Whose rules are you playing by? This tiny ad doesn't respect those rules:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!