• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Beginning in java

 
bala kan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,


I saw one mini project in which they use ms-access as back end and java as front end.. in which they used the following two lines to connect to the database


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
con = DriverManager.getConnection( "jdbc:odbc:lib");


can you explain me in detail why we have to use forName() and what it does


thanks in Advance
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since your question isn't in any way related to Swing / AWT / SWT, I've moved it to a more general section of the Ranch. Also, please go through the sections on "Use A Meaningful Subject Line" and "Use Code Tags" in How To Ask Questions On Java Ranch

Do you know how to find the Java API? Go through the documentation for Class#forName(...) and if you still don't understand, tell us what is confusing about it.
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bala, I see you didn't return to all but one of the threads you started. When other members spend their time to help you, they like to know whether the help offered was useful or not, and whether your question is answered adequately.

There's a section in the page I linked to titled SayThanks <- link Please go through that one too, or maybe just go through all the sections.
 
Ray Thibeault
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I won't cover the general use of Class.forName(). In this case, the call to Class.forName() will cause the specified java class to be loaded and its static code to be executed. This static code will register the database driver under the name "jdbcdbc:lib" in the JDBC driver list, thus allowing you to use it to open a connection in the following line.
Regards,
- R
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic