Setting Up MySQL for CS320This document describes how to set up a MySQL database server on your local computer for development, and how to use the MySQL server on CS3. A screen capture video demonstrating the process is available here. 1. Software InstallationInstall the MySQL database server as described in MySQL Database Server Installation. 2. Post Installation SetupThe purpose of this step is to create a local database setup that matches the one on the CS3 server, so you can run the same servlet/JSP code on both your local computer and on CS3 without any changes. Download the mysql-postinst.sql script. This script performs the following operations:
Edit the script so that the database name, the username, and the password match the ones for your account on the CS3 server, then run the script on your local MySQL. 3. Testing the Local Database SetupIf you have set up your development environment as described in Web Development with Eclipse and Tomcat, you would already have the MySQL JDBC driver installed; otherwise you will need to install the driver first. Create a servlet HelloJDBC.java. Use HelloJDBC.java as a template, and modify the source code so the database name, username, and password match your setup. Compile and run the servlet, and you should see following output: milk 3.89 2.0 Create a JSP page HelloSQL.jsp. Use HelloSQL.jsp as a template, and again, modify the database name, username, and password to match your setup. Run the page, and you should see:
4. Testing Database Access on CS3Connect to your MySQL database on CS3. Create a table items, then insert two rows into the table as follows:
Deploy your HelloJDBC servlet and HelloSQL.jsp on CS3, and they should produce the same results as in the previous step. |