wood burning stoves 2.0*
The moose likes JSP and the fly likes loading driver in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "loading driver in JSP" Watch "loading driver in JSP" New topic
Author

loading driver in JSP

nirali shah
Greenhorn

Joined: Apr 16, 2009
Posts: 24
Following code is from jsp page

String driver = "org.gjt.mm.mysql.Driver";
Class.forName(driver).newInstance();

In this code, driver = "org.gjt.mm.mysql.Driver" ; specifies driver to be loaded for mysql database.
Question is, this driver has to be in the system before it is loaded. How does the driver get in the system ? Does it come with the import of "java.sql.* " package ?
Is this only driver available to connect to mysql from jsp ?
How to find the exact name of the driver to load it ? I mean I did not know the driver name to connect to mysql db I saw before this code. If I have to connect to DB2, how to find the name of the required driver ? How to make sure that its in the package ?

thanks
Pravin Shirke
Ranch Hand

Joined: Apr 05, 2008
Posts: 150

Hi Nirali,
You can also add This Driver to your project

for this to work you need to add a jar to your projects. lib directory inside WEB-INF.

mysql-connector-java-3.0.17-ga-bin.jar

you can google it and download it. or go to official Mysql site and download the jar from there.
And for the driver which you have specified their's some thing like MM.something.something driver i am not sure about the jar file name so if you want to proceed with your driver. kindly google it and download the jar and add it to your project's lib directory inside WEB-INF.
hope this helps


[Vipassana] - It is seeing the reality as it is, And not as you want it to be.!!!
SCJP1.5.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

nirali shah wrote:
Question is, this driver has to be in the system before it is loaded.

Yes.
nirali shah wrote:
How does the driver get in the system ?

By putting driver's Jar file in classpath
nirali shah wrote:
Does it come with the import of "java.sql.* " package ?

No. 'java.sql' package provides the general class required to build JDBC code, also with 'Driver' class which has to be implemented by the Database Vendor in order to make JDBC driver.
nirali shah wrote:
Is this only driver available to connect to mysql from jsp ?

Interestingly, I never used/knew this driver, what I used for MySql is JConnector.
nirali shah wrote:
How to find the exact name of the driver to load it ? I mean I did not know the driver name to connect to mysql db I saw before this code. If I have to connect to DB2, how to find the name of the required driver ?

Consult the vendors page, asking about JDBC connection, If its MySQL, check there site,If its DB2, look at there site OR simple Consult Google

[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: loading driver in JSP