This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
vijay mahendra
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic