aspose file tools*
The moose likes JDBC and the fly likes who will call..Statement.excuteQuery() method. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "who will call..Statement.excuteQuery() method." Watch "who will call..Statement.excuteQuery() method." New topic
Author

who will call..Statement.excuteQuery() method.

vijay mahendra
Ranch Hand

Joined: Jan 01, 2007
Posts: 51
hi one and all,

we wrote code like this..

resultset =stmt.executeQuery();

but stmt is an interface... in which excuteQuery() method implemted internally..

thanks
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

This is a very common question, and knowing the answer should open up a whole world of understanding for you.

If you look at java.sql.*, almost everything is an interface. Who implements all of these interfaces? The JDBC driver! You know how you have to load a JDBC driver before you do anything else (typically with Class.forName()?) Well, that class that you load by name registers an instance of a class that implements java.sql.Driver with the JDBC driver manager. When you try to connect to a database, the driver manager asks that Driver for an instance of an object that implements the Connection interface. When you ask that Connection for a Statement, it returns an instance of a class that implements Statement -- and so on. The reason it's done this way is that connecting to each different database requires different code internally, but by using this common set of interfaces, your database code can be largely independent of the database you use! You can switch database by using a different driver. You get a whole different set of classes to work with, but since you only reference them through the interfaces they implement, your code doesn't have to change at all!


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: who will call..Statement.excuteQuery() method.
 
Similar Threads
garbage collection
NX: When should I throw DuplicateKeyException?
Finalization Method
Sharpen your Pencil - Page 323 in HFEJB
Changin font in a JTextArea