Tomcat6 can't connect to MySql (The driver has not received any packets from the server)

元气小坏坏 提交于 2019-11-29 04:35:32

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 :)

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
Rahul Kumar
Class.forName("com.mysql.jdbc.Driver");
            con=DriverManager.getConnection("jdbc:mysql://localhost:3306/indiadb","root","root");

Check:

  1. the port number it must be only 3306

  2. 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!