Installing a JDBC Driver

printer-friendly version of this section  Print  e-mail this section  E-Mail  add a public, group or private note  Add Note  add a bookmark about this section  Add Bookmark    

JSTL: JSP Standard Tag Library Kick Start
By Jeff Heaton

Table of Contents
Appendix C.  Installing MySQL


For Java to use a database, you have to have a JDBC driver. Several drivers are available that you can use. The driver that we use in this book is the MM driver, which you can download from http://mmmysql.sourceforge.net/. If you followed the instructions in Appendix B, you won't need to install the MM driver. The examples download contains the MM driver already properly installed.

The MM driver is distributed as a JAR file named mm.mysql-2.0.14-you-must-unjar-me.jar. This is not an ordinary JAR, and it cannot be used directly by Java. The author of MM is simply using JAR as an archive format, similar to Zip. The easiest way to extract from this archive is to rename it to a .zip file and use a Zip tool.

Once you access the contents of this archive, locate the MM JAR file, which should be named mm.mysql-2.0.12-bin.jar or something similar. You must make this file accessible to the classpath. For the purposes of this book, this involves placing the file in the directory C:\Program Files\Apache Tomcat 4.0\webapps\ROOT\WEB-INF\lib.

Now that you have the MM driver installed, you are ready to use MySQL from JDBC. To access any driver from JDBC, you must know the driver name and the URL of the database. The driver name for the MM driver is org.gjt.mm.mysql.Driver, and the URL is jdbc:mysql://localhost/forum?user=forumuser. To use this information in JSTL, use the following <sql:setDataSource> tag:

<sql:setDataSource var="dataSource" driver="org.gjt.mm.mysql.Driver" url="jdbc:mysql://localhost/forum?user=forumuser" scope="session" /> 

See Chapters 7 and 11 for more information about using databases from JDBC.


    printer-friendly version of this section  Print  e-mail this section  E-Mail  add a public, group or private note  Add Note  add a bookmark about this section  Add Bookmark    
    Top

    [0672324504/app03lev1sec4]

     
     


    JSTL. JSP Standard Tag Library Kick Start
    JSTL: JSP Standard Tag Library Kick Start
    ISBN: 0672324504
    EAN: 2147483647
    Year: 2001
    Pages: 93
    Authors: Jeff Heaton

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net