• Post Reply Bookmark Topic Watch Topic
  • New Topic

Interface-Resultset  RSS feed

 
Thakur Sachin Singh
Ranch Hand
Posts: 248
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

can any one tell me...ResultSet is a interface it means we can only create reference variable of this interface and store objects of classes which implements this interface.

please tell me those classes names in which we implements this interface???
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The specific classes that implement ResultSet will depend on the database driver (which means we don't usually implement it, unless we're writing database drivers). For instance, the Oracle JDBC drivers contain a class oracle.jdbc.driver.OracleResultSet.

If you ever really want to know the class implementing the ResultSet you've got, just print out resultSet.getClass().getName().
 
Prabaharan Gopalan
Ranch Hand
Posts: 66
Java Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ResultSet is an interface, alright. But the implementation will be provided by the implementors of the JDBC API. As you might have known, the JDBC API will be implemented by the database providers. So, you'll have ojdbc.jar, mysql.jar, pgsql.jar (or similar names). These jars will contain the database specific ResultSet implementation.

Hope this answers your question.
 
Prabaharan Gopalan
Ranch Hand
Posts: 66
Java Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Beat me by half a minute, Matthew.
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You generally don't need to know the class name. You'll obtain the implementation of this interface from appropriate JDBC methods (such as PreparedStatement.executeQuery()); the concrete class implementing the interface is JDBC driver specific.

In some rare cases you might want to call a driver specific method of the implementing class. In this case, you'll need to consult the JDBC driver documentation to find out the class name (so that you can cast the instance into the proper class) and find out the specific methods you want to call. Usually this is again an interface extending java.sql.ResultSet which declares some additional methods (for example oracle.jdbc.OracleResultSet for Oracle JDBC driver), and you still don't need the name of the implementing class. you should try to avoid this as much as possible, though; you obviously lose database independence and obtaining such class can be less straightforward when using connection pooling (among other reasons).

And I've come ten minutes too late...
 
Thakur Sachin Singh
Ranch Hand
Posts: 248
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:The specific classes that implement ResultSet will depend on the database driver (which means we don't usually implement it, unless we're writing database drivers). For instance, the Oracle JDBC drivers contain a class oracle.jdbc.driver.OracleResultSet.

If you ever really want to know the class implementing the ResultSet you've got, just print out resultSet.getClass().getName().


Matthew...is resultSet is a predefined object?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thakur Sachin Singh wrote:Matthew...is resultSet is a predefined object?

No, I was hoping it would be clear that was just a variable referencing whatever ResultSet you have. Obviously not .

I meant something like this:

But remember that, as Martin says, you shouldn't need to know what the underlying class is. Check it out for your own curiosity if you want, but never write code that relies on it being a specific type.
 
Thakur Sachin Singh
Ranch Hand
Posts: 248
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hummm i have clear my doubt...thank you all for yours valuable answers...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!