What Class.forName( ) method will do


Answered by Jey Ramasamy on 2005-05-10 05:50:07: Class.forName() is used to load the Driver class which is used to connect the application with Database. Here Driver class is a Java class provided by Database vendor.

Showing Answers 1 - 15 of 15 Answers

Jey Ramasamy

  • May 10th, 2005
 

Class.forName() is used to load the Driver class which is used to connect the application with Database. Here Driver class is a Java class provided by Database vendor.

  Was this answer useful?  Yes

Kasthuri Aravamudhan

  • Jun 17th, 2005
 

de facto of driver class contains static block which will be loaded when call it in init() method. As per performance issue using more number of static values or block in ur java class will degrade the performance but driver class is exceptional one where vendors right methods and driver utilities in static block. So u have to call Class.forName() to use the driver methods 
 
you can define connection method ,jndi context ,user defined resource in init method for good performance of jdbc.

  Was this answer useful?  Yes

kishoredvs

  • Jul 12th, 2005
 

Class.forName() will load the class dynamically and it will return the object of type class.

  Was this answer useful?  Yes

Aditya

  • Jul 28th, 2005
 

Can somebody tell what if i register 2 different drivers one by one using class.forName().  
Which driver I will get during the connection.

  Was this answer useful?  Yes

nomaan khan

  • Aug 1st, 2005
 

Class.forName() loads all the needed classes for the corresponding driver

  Was this answer useful?  Yes

Selvaraj

  • Aug 8th, 2005
 

One can use any number of Class.forName(); 
For example, 
one for oracle driver 
one for Sql server 
 
because,Class.forName(Driverclass ) used for 
 
1. loading particular drivers. 
2. Creating the instance of the driver. 
3. Registering driver instance with DriverManager 
 
DriverManager maintains the all the register drivers. 
 
only the connection statement determine, which db is to be connection(either oracle or sql server) 
so what url u passed, based on that connection will be created. 
 
when we look at the syntax for connection 
 
Connection con =  
 
DriverManager.getConnection("jdbc:subprotocol:DriverName:@hostname:portno:dbname",  
 
username,password); 
 
Subprotocol, portno ,Drivername is different for diferent for oracle, sql server 
 
so connection will be created based on what url u r passing in DriverManager.getConnection()  
 
method,and doesn't depend on how many Class.forName(DriverclassName ) statement used. 
 
so the connection is based on url passed

chandra

  • Sep 19th, 2005
 

Can somebody tell what if i register 2 different drivers one by one using class.forName(). Which driver I will get during the connection.

  Was this answer useful?  Yes

jitendra singh

  • Sep 30th, 2005
 

Class.forName() method intialize the specified driver Class and load it in to the main memory

  Was this answer useful?  Yes

pankaj batra

  • Jan 6th, 2006
 

exact answer for class.forName() from Orielly

It registers the driver class to Drivermanager and loads it.

If there are more than one statement of Class.forName which is configured for different Database

DriverManager.getconnection("url","username","password")

Then DriverManager send message to every Driver registered to it and whichever Driver Recognise that URL will give the connection.

For more details

JDBC API from Servlet Programming by Orieely

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions