Setting up your Windows computer to run JPetStore 3.x with MySQL and Tomcat
Author: | Adrian Lanning |
Date: | 01-27-04 |
Version: | 2.2.2 |
Table of Contents
- Revision History
- Motivation
- Special Note: Transactions
- Walkthrough
- Java
- Tomcat
- JPetStore - Download
- MySQL
- MySQL JDBC Driver
- JPetStore - Database
- JPetStore - Deploy
- JPetStore - Driver Setup
- Troubleshooting
- No action instance for path /shop/index could be created
- Error getting transaction
- Can't get Transactions to work on Red Hat 9.0! / Edited my.cnf - Now Mysql doesn't start!
- Comments
- My personal site / Tutorial Requests - by Adrian Lanning
- Linux - Transactions / INNODB / my.cnf - by Adrian Lanning
- Transactions / INNODB / my.cnf - by Chris Smith
- Create User / GRANT usage - by Chris Smith
- Access Denied / GRANT usage - by Marc Mulzer
- Linux Install - by George Entenman
- Solaris Install - by Christoph Kutzinski
Revision History
Version 2.2.2 - 02/13/04- Added new troubleshooting ticket on setting up transactions on Red Hat 9.0.
- Added new comment on setting up transactions on Red Hat 9.0.
- Updated JPetStore sql scripts to use a lowercase jpetstore database name for better compatibility with *nix systems.
- Added Christoph's comment on installing JPetStore on Linux.
- Added comment on installing JPetStore on Solaris.
- Added 'USE JPETSTORE;' line to top of 'jpetstore-mysql-dataload.sql' file as Chris Smith recommends.
- Added link to 'jpetstore-mysql-schema-innodb.sql' file Chris sent me.
- Added a comments section where helpful correspondence will go.
- Shifted hosting to my personal website.
- Added links to sql scripts and made minor changes to JPetStore - Database.
- Changed tutorial to HTML format.
- Included Linux-Friendly MySQL scripts (thanks to Maria Tzvetanova).
- Original Writing
Motivation
I made this walkthrough in the hopes of saving someone some time when installing Clinton Begin's excellent JPetStore application.
This guide will walk you through the steps involved in setting up a Windows system to run JPetstore. It does not assume any prior installation/configuration of dependent software.
Linux / Solaris 9 Note:
The steps in this walkthrough are generally the same for a Linux or Solaris 9 installation.
George let me know how he got JPetStore to work on Linux and Christoph let me know how for Solaris 9.
Maria Tzvetanova pointed out that the lowercase table names in the mysql setup scripts In Version 1 caused errors when used on Linux systems. This is because (unlike Windows) MySQL on Linux is case-sensitive. She has supplied updated mysql scripts with uppercase table names which are included in Version 2.
Special Note: Transactions
The MySQL scripts that come with this walkthrough set up tables of the default (ISAM) type. These tables do NOT support transactions but are very fast. The MySQL driver is smart enough to act as if transactions occur so that transaction-aware software (like JPetStore) will still run fine. But in reality, each SQL command is a seperate "transaction".
If you need transaction support, use the MySQL script that comes with the JPetStore distribution (in the ddl/mysql directory). That file uses INNODB tables which do support transactions.
You will still need to set up a user so you can still use the jpetstore-mysql-create-user.sql script.
Note: Check out Chris Smith's helpful comment regarding the use of INNODB tables.
Chris sent me a modified version of the INNODB schema script that comes with JPetStore which supports re-running the script to reset the database to the starting state. See the above comment.
Walkthrough
- Java
- Download Java SDK 1.4.2_01 (had trouble using the NetBeans bundle so I recommend using the regular SDK package).
- Tomcat
- Download and install the latest version of Tomcat from http://jakarta.apache.org/site/binindex.cgi.
- I install all my Apache apps to "c:\program files\apache" to keep it simple.
- Just keep all the other defaults the same, and input your preferred admin password when prompted.
- Start Tomcat. You can use either the Windows Service or the Start Menu shortcut, "Start->Programs->Apache Tomcat 5.0->Start Tomcat".
- Verify that Tomcat is working correctly.
- Goto http://localhost:8080. If you see a Tomcat base page you're good.
- Goto http://localhost:8080/jsp-examples and try out a couple of the examples to confirm that Tomcat is working properly.
Note: I had trouble getting the example, http://localhost:8080/jsp-examples/jsp2/misc/config.jsp to work. To fix this exception I followed the on-screen instructions and copied "$JAVA_HOME/lib/tools.jar from the JDK to the common/lib directory of the Tomcat server, followed by a Tomcat restart." :) - JPetStore - Download
- Download and unzip the latest version of JPetStore to a temp directory.
- MySQL
- Download MySQL 4.0.14b, unzip, and run Setup.
- Goto your default MySQL directory (C:\mysql for me) and copy my-medium.cnf to my.cnf. Now move my.cnf to C:\.
- Open a command prompt (Dos prompt). Now goto, "C:\mysql\bin" and run, "mysqld-nt -install". This will install the MySQL daemon (server) as a Windows Service that will start automatically when Windows starts. You can verify this by going to Start->Control Panel->Administrative Tools->Services under Win2000.
- Start the MySQL Service.
- Win2000:
- Go to Start->Control Panel->Administrative Tools->Services.
- Double-click the MySQL service
- click the Start button.
- Set Root MySQL password. *** Very Important Step ***
- Goto "C:\mysql\bin".
- Run "mysqladmin -uroot password NEW-PASS" where NEW-PASS is your password of choice.
Note:Don't type the quotes...
- Verify MySQL is running correctly.
- Run "mysql -uroot -p". You will be prompted for a password. Just enter in whatever you typed for NEW-PASS.
- You should see a "mysql>" prompt. If not, check Google for whatever error code you received.
- Run "show databases;".
Note: Don't forget the ';'. If you ever see a prompt with just a " ->" then you know you forgot the ';'. - If you don't see,
+----------+ | Database | +----------+ | mysql | | test | +----------+ 2 rows in set (0.02 sec)
then you know something is wrong...try Google.
- MySQL JDBC Driver
- Download the MySQL JDBC Driver, mysql-connector-java-3.0.9-stable.
- Unzip the driver. Copy the file, "mysql-connector-java-3.0.9-stable-bin.jar" to Tomcat's common/lib directory.
- JPetStore - Database
- Now download these files to your computer:
jpetstore-mysql-schema.sql
or jpetstore-mysql-schema-innodb.sql if you want transaction support (see Chris's comment).
jpetstore-mysql-dataload.sql
jpetstore-mysql-create-user.sql
- Make sure you logged out of mysql, jump back to your shell prompt, and execute the following commands.
- "mysql -uroot -p < jpetstore-mysql-schema.sql" OR "mysql -uroot -p < jpetstore-mysql-schema-innodb.sql" for transaction support.
- "mysql -uroot -p < jpetstore-mysql-dataload.sql"
- "mysql -uroot -p < jpetstore-mysql-create-user.sql"
- If you don't see any errors, it worked correctly.
- JPetStore - Deploy
- Find jpetstore.war in the build/wars folder of wherever you unzipped the JPetStore download to.
- Copy jpetstore.war to your Tomcat/webapps folder. For me this was at "C:\Program Files\Apache\Tomcat 5.0\webapps". Tomcat will automatically deploy your app if you have it started. If it's not started just follow the instructions in step 2.
- Don't try to access (run) the app yet.
- JPetStore - Driver Setup
- Find /webapps/jpetstore/WEB-INF/classes/properties/petstore.properties from your Tomcat directory. (c:\program files\apache\tomcat 5.0, for me)
- Change the default (oracle) values to match the following:
SimpleDriver=org.gjt.mm.mysql.Driver SimpleUrl=jdbc:mysql://localhost:3306/jpetstore SimpleUsername=jpetstore SimplePassword=ibatis9977
- Save it!
- Test
- Shutdown and restart your Tomcat Web Server by either stopping the Service or using the System Tray icon.
- Once Tomcat has restarted, click here (link will open a new window): http://localhost:8080/jpetstore .
- Have fun!
Troubleshooting
I figured I'd try to do things wrong and see what errors I got in case it happens to one of you. :)
Message: HTTP Status 500 - No action instance for path /shop/index could be created Description: The server encountered an internal error (No action instance for path /shop/index could be created) that prevented it from fulfilling this request.I got this error by deleting the JDBC driver from Tomcat's common/lib directory. If you see this error, follow the directions in Step 5, and then restart the Tomcat server.
Note: The "No action instance for path ..." error will occur ANY time Tomcat can not instantiate an action (usually because it can't find a required library / jar file) so there are many different reasons why you might be getting this error.
In general, check the log files in %CATALINA_HOME%/logs and see if you can find what's causeing the error.
Unhandled Exception: com.ibatis.db.dao.DaoException: Error getting transaction. Cause: java.sql.SQLException: Invalid authorization specification, message from server: "Access denied for user: 'jpetstore@localhost' (Using password: YES)" <---- Caused by: java.sql.SQLException: Invalid authorization specification, message from server: "Access denied for user: 'jpetstore@localhost' (Using password: YES)" ---->I got this error by deleting the jpetstore@localhost user from MySQL. See Step 6.
Note: While porting the iBATIS JPetStore to use MySQL I had a big problem where I got this error even when I had clearly created a 'jpetstore' user. After trying a few things out, I found out you have to make the user as 'jpetstore@localhost' rather than 'jpetstore' in order for this to work. If anybody knows why this occurs, please let me know.
Note: Several people have emailed me with helpful comments regarding this error. See Chris's comment and Marc's comment below.
040213 22:34:42 mysqld ended 040213 22:34:48 mysqld started InnoDB: Error: log file /var/lib/mysql/ib_logfile0 is of different size 0 5242880 bytes InnoDB: than specified in the .cnf file 0 67108864 bytes! 040213 22:34:48 Can't init databases 040213 22:34:48 AbortingFor a more thorough look at this problem see my comment below.
I recently set up INNODB transactions on Red Hat 9.0 and had problems. My Red Hat 9.0 came with mysql installed. I thought transactions were working but they weren't. I found there was no my.cnf file (usually at /etc/my.cnf).
I copied my-large.cnf to /etc/my.cnf and changed it to fit my system as per the
InnoDB Reference Manual
Then I tried restarting mysql...no luck. Nothing happened.
Found the above error in the innodb error log file.
Solution
This only works if you don't care about your innodb transaction backups! Although to get this error, InnoDB probably wasn't working in the first place.
Just move those log files to ib_logfile0.bak, ib_logfile1.bak, etc. and start mysql again.
Consequences
This solution is not elegant but it works. At least it worked for me because I didn't have any real data in the innodb tables anyways. INNODB stores all transactions in it's log files so by moving those, I probably erased all the backups of my transactions. If you have data you need to save, you'll have to get help from someone wiser than me. ;)
Comments
One of the best parts about sharing online is getting great feedback. I've included what I felt to be the most useful / most frequently asked comments from the community.
Note: SDF is a non-profit corp. offering a website, mail, and unix shell access for a $36 one-time fee! (And no I'm not getting paid to say that.)
I've been a member for about a year now and a friend of mine has been for over 10 years.
Chris writes in his comment below:
I recently set up INNODB transactions on Red Hat 9.0 and had problems. I'd like to share their solutions here.
Ok, my Red Hat 9.0 came with mysql installed. The regular INNODB files were also in the mysql data directory:
So I thought transactions might be working. I tried my app out and found that although I had set the table type to INNODB, transactions were, in fact, NOT working.
Then I remembered Chris's comment and checked the my.cnf file. On Linux it is usually located at:
I checked but it wasn't there. So I searched the whole computer:
Still no luck.
Ok, so I'll make my own.
I copied my-large.cnf to /etc/my.cnf and changed a few settings to fit my system as per the InnoDB Reference Manual.
Then I started up mysql again using the Red Hat service script...
Nothing happened.
Now on Red Hat 9.0, the mysql service script (located at /etc/rc.d/init.d/mysql) uses safe_mysqld. safe_mysqld will not output any error messages to the console, they all get logged. So checking the SERVERNAME.err log file (where SERVERNAME is your server's name), I found this error message:
So now I know what the problem is...
The solution?
Well I just moved those log files to ib_logfile0.bak, ib_logfile1.bak, etc. and started mysql again.
Consequences
This solution is not elegant but it works. At least it worked for me because I didn't have any real data in the innodb tables anyways. INNODB stores all transactions in it's log files so by moving those, I probably erased all the backups of my transactions.
Note: I use INNODB tables and upon checking my my.cnf file, I found that I did not have the INNODB sections uncommented. Transactions appear to be working for me so those lines may just override some default settings in MySQL.
In any case, I'm gonna be safe and follow Chris's advice.
Well, I'm happy to say that someone finally sent me instructions on how to install JPetStore for Linux! Thanks George!
Note: MySQL database url's on Solaris and Linux are apparently case-sensitive. I would imagine that if you changed the SimpleUrl attribute in petstore.properties file to:you wouldn't have to change the sql files...
If anybody tests this out and it works, please let me know.
Christoph got JPetStore working on Solaris, and let me know how. Thanks Christoph!
Note: MySQL database url's on Solaris and Linux are apparently case-sensitive. I would imagine that if you changed the SimpleUrl attribute in petstore.properties file to:you wouldn't have to change the sql files...
If anybody tests this out and it works, please let me know.