Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ResultSet

 
Ananth Ram
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

What type of object is returned when a ResultSet is executed??

Tx,
Karthik
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ResultSet never get executed. Its the statement which get executed. When a statement is executed a resultset is returned which contains all the records which the specified statement has fetch.
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To add a little to the previous response, when dealing with a Statement, there are three types of execute methods:

1) "executeQuery()" is used for doing a SELECT statement, and will return a ResultSet.

2) "executeUpdate()" is used for doing a DELETE, UPDATE or INSERT statement, and will return an int (number of rows affected).

3) "execute()" is used for multiple operations, or when the query type is unknown, and will return a boolean (read the doc as to the meaning since it's too complicated to explain here).

Some databases will let you get away with calling "executeQuery()" with a DELETE, UPDATE or INSERT, and others are more strict. But it's good to get in the habit of calling the appropriate method.

While it's true that you can't execute a ResultSet, with the JDBDC 2.0 specification you can udpate the database via the ResultSet. The methods are all "void", so don't return anything.

Cheers ...
[ May 20, 2004: Message edited by: Wayne L Johnson ]
 
Ananth Ram
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meant when statement is excuted ResultSet is returned and what is the nature of it, is that in the form of objects, records, etc...??
[ May 24, 2004: Message edited by: Karthik Ganesh ]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34396
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karthik,
Well, the easy answer is that everything is an object.
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When statement is executed it return the object of ResultSet. This resultset object contains all the data from database table which is returned by your specified query.

You can navigate resultset using its next() and previous() methods or fist() and last() methods. You can get the data against any column using getXXX() methods of Resultset.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic