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

jdbc statment creation

 
amrut sabade
Ranch Hand
Posts: 90
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone we learned in core java that we can't create an object of Interface,... and in jdbc statment is an and interface so how do we create an object of statement?
please clear my doubt
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We don't, unless we are JDBC driver writers. Interfaces need implementations otherwise you can't use them. The JDBC driver provides implementations of all the JDBC interfaces for whatever database it connects to. When you call createStatement() its the implementation that is returned. Try writing:

to find out what that implementation is.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47232
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think whoever said "can't create an object of an interface" has misunderstood implementation. You can create an object of an interface, but indirectly, by implementing it. You can create a class which implements that interface, either as an ordinary (concrete) class or an anonymous class. Remember you can do this in several stages in an inheritance hierarchy, some of which stages might be abstract classes or other interfaces.Here the Statement object "hides" an implementation of the ResultSet interface which is what is actually returned. So the statement implements the interface ResultSet and returns an object of that implementation, which is an object of ResultSet. Have a look at my Engine and GrowingPlant examples from three years ago. Read that discussion. Find the lineand change it toChange "Tree" to "GrwoingPlant" in all the for-each loops. See whether you can see any difference in the output.

Ad a few lines to the original classesAdd a new classNow see what happens. Every member of the "trees" array is an instance of the GrowingPlant interface. Create the Lithops class, where the plant grows 1mm taller every time.
 
amrut sabade
Ranch Hand
Posts: 90
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hii thank s s o much i got the concept..thanks for giving such a nice explenation
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic