• 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

establishing database connection

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can any one explain the code given below and why are we using.
class.forName(("sun.jdbc.odbc.JdbcOdbcDriver");

explanation required other then " used for loading the database driver ".
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, it loads the Driver :-)

ok, here is my shot at it:

if you run this code:




then you will see following output:


Now Executing main()
Now intializing Driver properties



when calling Class.forName("foo.bar.Baz") then you create an instance of java.lang.Class (not an instance of the class foo.bar.Baz). This Class object "specifies" the foo.bar.Baz class. From it you could create new instances with the newInstance() method or trough other reflection techniques. But the important thing is that when you create a Class file, its stastic blocks are executed. I think (never checked the source code of a JDBC driver) this is what happens in your JDBC drivers. DB/Driver specific properties are set and initialized....

pascal
[ December 30, 2004: Message edited by: pascal betz ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic