• Post Reply Bookmark Topic Watch Topic
  • New Topic

establishing database connection  RSS feed

 
veeramani velayutham
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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 ".
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • 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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!