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

后端 未结 4 911
说谎
说谎 2020-12-17 01:22

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

相关标签:
4条回答
  • 2020-12-17 01:23

    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
    
    0 讨论(0)
  • 2020-12-17 01:23
    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

    0 讨论(0)
  • 2020-12-17 01:25

    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.

    0 讨论(0)
  • 2020-12-17 01:31

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

    0 讨论(0)
提交回复
热议问题