Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Beginning in java

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 "jdbc:odbc:lib" in the JDBC driver list, thus allowing you to use it to open a connection in the following line.
Regards,
- R
 
What a stench! Central nervous system shutting down. Save yourself tiny ad!
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic