This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 24183
    
  34

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]
 
 
subject: who will call..Statement.excuteQuery() method.
 
Similar Threads
NX: When should I throw DuplicateKeyException?
Changin font in a JTextArea
Finalization Method
Sharpen your Pencil - Page 323 in HFEJB
garbage collection