Tomcat 7 与 MySql
我使用 Mac OSx 10.6 并希望将 Tomcat 7 服务器与 MySql db 一起使用。我的 context.xml 文件:
<?xml version='1.0' encoding='utf-8'?>
<Context>
<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
maxActive="100" maxIdle="30" maxWait="10000"
username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/javatest"/>
</Context>
和我的部署描述符:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:javaee="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_ID" version="2.4">
<display-name>Love Finder</display-name>
<servlet>
<servlet-name>customer</servlet-name>
<servlet-class>com.neya.love.finder.pl.CustomerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>customer</servlet-name>
<url-pattern>/customer.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
我有表 javatest
但当连接到数据库时,我遇到了这个异常:
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (null, message from server: "Host '192.168.0.100' is not allowed to connect to this MySQL server")
有人可以帮助我吗?
I use Mac OSx 10.6 and want to use Tomcat 7 server with MySql db. My context.xml file:
<?xml version='1.0' encoding='utf-8'?>
<Context>
<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
maxActive="100" maxIdle="30" maxWait="10000"
username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/javatest"/>
</Context>
And my deployment descriptor:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:javaee="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_ID" version="2.4">
<display-name>Love Finder</display-name>
<servlet>
<servlet-name>customer</servlet-name>
<servlet-class>com.neya.love.finder.pl.CustomerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>customer</servlet-name>
<url-pattern>/customer.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
I have table javatest
but when make connection to db I have this Exception:
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (null, message from server: "Host '192.168.0.100' is not allowed to connect to this MySQL server")
Can someone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您将需要授予该服务器权限。 MySQL 需要用户名、密码和客户端 IP。
http://dev.mysql.com/doc/refman/5.1 /en/adding-users.html
You will want to GRANT permissions to that server. MySQL requires username, password, and client IP.
http://dev.mysql.com/doc/refman/5.1/en/adding-users.html
您可能需要检查您的 MySQL 配置文件 (my.ini) 是否包含以下条目:
You might want to check if your MySQL configuration file (my.ini) has the following entry:
您可以在计算机上使用 MySQL Client 进行连接吗?
在 shell 类型中
如果不是,那么 duffymo 可能是正确的。
Can you connect using the MySQL Client on the computer?
In a shell type
If not then duffymo is probably correct.