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. |