嗨,大家好,我是J2EE的新手(但不是Java),并且我面对着Tomcat和Java数据源的一个问题。
问题是当我调用datasouce.getConnection()时,服务器日志中充满了异常,但是该应用程序运行正常(它能够从db中获取数据)
我的context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<!-- Specify a JDBC datasource -->
<Resource name="jdbc/thmstordb" auth="Container"
type="javax.sql.DataSource" username="myuser" password="mypass"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/themestore?profileSQL=true"
maxTotal="10" maxIdle="4" />
</Context>
我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>ThemeStore</display-name>
<servlet>
<servlet-name>themestore-servlet</servlet-name>
<servlet-class>
com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.mmx.services</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>themestore-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/thmstordb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
例外情况:
https://drive.google.com/file/d/0B71OH33lwaXwcUZLTTBPdFpxeFk/view?usp=sharing
有人可以帮助我,我可以做些什么来消除这些例外。
最佳答案
为了完整起见(因为它似乎有效):
您是否尝试过从连接字符串中删除profileSQL=true
?也许此错误http://bugs.mysql.com/bug.php?id=70677导致了问题。
关于java - Tomcat数据源getConnection工作,但在日志中引发异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32165887/