File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Beginning in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Beginning in java" Watch "Beginning in java" New topic
Author

Beginning in java

bala kan
Ranch Hand

Joined: Aug 20, 2012
Posts: 44
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

Joined: May 03, 2008
Posts: 4523
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

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

Joined: Jul 25, 2012
Posts: 3
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Beginning in java
 
Similar Threads
Connection Pool question
How can I use COM component in java
How to send SOAP request from Java
[GWT Java AJAX Programming book] General qualification
Java Vs VB