• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jdbc statment creation

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hii thank s s o much i got the concept..thanks for giving such a nice explenation
reply
    Bookmark Topic Watch Topic
  • New Topic