Can't connect to MySQL database from tomcat

安稳与你 提交于 2019-12-05 18:23:58

The driver is wrong - use the "com.mysql.jdbc.Driver" class.

Scriptlet code in a JSP? Oh, my - that's not good.

But those are not the cause of your problem.

Did you GRANT permissions to that username and password? Here are sample steps:

  1. Log in as root: mysql –h localhost –u root –p <ret>; password = <your admin password>
  2. “create database x;”
  3. “create user p identified by ‘q’;”
  4. “grant all on x.* to ‘x’@’%’;”

Give the username p and password q you used to create the user when you connect to the database.

Make sure the service is up and listening on port 3306. Open a command shell and type 'netstat -a' and look for a listener on port 3306.

This entry from the MySQL bug database might be pertinent as well.

For future reference, I find it helpful to paste whatever error message I get into Google. It's likely that I'm not the first person to run into a particular problem.

Even if you manage to solve this and get it to work, this is still a fatally flawed design. The JSP is connecting directly to the database - no security, except for the username and password you've entered in plain text. You really don't want to do this.

You're having a connection problem. Separate that from the JSP for starters.

  1. Can you connect using the MySQL admin tool in a command shell?
  2. Can you write a simple Java class to connect successfully to the database?

I downgraded MySQL from 5.1 to 5.0 and everything is working now. Must be some sort of bug in the 5.1 version.

Well thanks for the help :)

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