View Full Version : Java/JSP/Servlet Connect To MySQL database

06-08-2004, 02:37 PM
I just use west host service recently.

I want to run a jsp/java/servlet application in tomcat connected to a MySql db.

Current status:
java/jsp/servlet work fine.
mysql db works fine.
but I cannot let them connect to each other.

I tried to place mysql-connector-java......jar file into /var/tomcat4/common/lib, then restart the virtual server of westhost,
but my program still not run.

What I have set:
driverName = "com.mysql.jdbc.Driver";
dbURL = "jdbc:mysql://"

Where should I place the mysql connector jar file in tomcat4.
What dbURL should I use.

If possible, please help.
Many thanks in advance.


07-13-2004, 04:21 PM

Well this should make it work. (maybe)

Set MySQL to use the TCP/IP option (WARNING: Security issue)
Then make your connection use the IP address of your domain, or the domain name (not, Port# is optional.

I would recommend updating your mysql tables of db, host, and user, to only allow from your 3 known servers (localhost, <domain name>, <domain ip>). Do not know if this will work on anything less than a Value package (value is the last one with static IP).

Now backup your /etc/my.cnf file somewhere (maybe /etc/my.old.cnf)
then remove the [client] section, remove in the [mysqld] section port, user, and bind-address lines. Then save it. Kill your sql server (both the safe-mysqld, and the first process of the mysqld processes)
Maybe /etc/rc.d/init.d/mysqld restart will do the trick.

the start the mysqld server (unless you tried the restart option) /etc/rc.d/init.d/mysqld start.

Seems to do the trick..... YMMV.