i\'m running an Apache Tomcat 6.0.20 / MySQL 5.1.37-lubuntu / sun-java6-jdk /sun-java6-jre / sun-java6-bin on my local machine using Ubuntu 9.10 as OS. I\'m trying to get a
I had the same issue.
It turns out I messed up the server by running three mysqld instances, so kill the unwanted resolved my issue:
me@ubuntu:~$ ps aux | grep mysql
mysql 8149 0.1 0.4 280484 26008 ? Ssl 13:24 0:00 /usr/sbin/mysqld
me 8256 0.0 0.0 4392 836 pts/3 S+ 13:24 0:00 grep --color=auto mysql
root 26569 0.0 0.0 5952 1856 ? S 10:44 0:00 sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking
mysql 26570 0.1 0.6 323528 41936 ? Sl 10:44 0:15 /usr/sbin/mysqld --skip-grant-tables --skip-networking
me@ubuntu:~$ sudo kill 26570
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/indiadb","root","root");
Check:
the port number it must be only 3306
Add the mysql.jar
in lib if you are using Tomcat6
Please try with an "official" Connector/J 5.1 i.e. distributed by MySQL, not a deb (note that I have nothing against deb).
Also please enable --log-warnings
on the mysql server and see if anything is showing up in your error logs.
I solved this problem. The reason why this error occurs is tomcat security restrictions.
You have to add following line to your $TOMCAT-CONFIG/policy.d/04webapps.policy
permission java.net.SocketPermission "127.0.0.1:3306", "connect";
Works for me, hope it will work for you too :)