/****************************************************** * CONNECT TO MYSQL DATABASE USING TOMCAT AND JSP * Date: 08/11/2006 Location:CCRC *******************************************************/ 1. Download the latest release (get the beta if it is the latest) of MYSQL (5.0 @time) from http://mysql.com 2. Perform basic configufation - if you have not used MySQL for some time and you forget your password. a. uninstall MYSQL from the Control Panel, restart your computer and delete it physically b. re-install the latest version of MySQL c. Remove the existing instance if error 1045 occurs d. reconfigure and create a new account e. For this error 'cannot create windows service for MySQL error:0' at the command line type - sc delete mysql (or all variants of it) - your default user name is always (root) and (root@localhost) where necessary - the default port is 3306. you do not need to include this in the url connection string when attempting to establish a connection 3. Download MySQL Connector/J (this is EXTREMELY important) - ALWAYS download the latest release of Connector/J (3.2 @time). Earlier releases are known to have bugs that can make connection a nightmare.....trust me I know all about it. - First, add the path directory for the mysql-connector-java....jar file to your CLASSPATH, not your PATH - Copy this mysql-connector-java....jar file in the $CATALINA_HOME/common/lib directory and the the WEB-INF/lib directory of the Web Application you intent to use for your database connection e.g. ROOT or any directory you have created in $CATALINA_HOME/webapps for this purpose - Finally also copy this mysql-connector-java....jar file in the C:/Program Files/Java/jdk1.5.0_07/jre/lib/ext directory, just in case you might need to make MySQL connections from a Java IDE, such as Eclipse or NetBeans 4. Create your JSP file - now you can create your .jsp file and place it the root of the special directory you created to hold your database connection Web Application - This directory should at this point contain a WEB-INF/lib/mysql-connector-java......jar file - in your .jsp file your url connection string should look like String connectionURL = "jdbc:mysql://localhost/dbName"; - do not write "jdbc:mysql://localhost:3306/dbName", Tomcat does this automatically - load the driver using Class.forName("com.mysql.jdbc.Driver").newInstance(); - and establish the connection using connection = DriverManager.getConnection( connectionURL, "rootisalwaysdefaultuser", "whateveryourpasswordis"); 5. Pat yourself on the back if it doesnt take 6 hours to figure this out