gpt4 book ai didi

java - 基本直接的 Tomcat-MySQL 链接

转载 作者:行者123 更新时间:2023-11-28 23:38:32 26 4
gpt4 key购买 nike

我已经尝试了几个星期,试图在 Apache Tomcat 7 服务器和 MySQL 5 之间建立一个非常基本的直接链接,但没有成功:

HTTP Status 500 - javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for jdbc/MySQL"

这是我的 server.xml 当前的样子:

<Server>
<Service name="Catalina">
<Connector port="80" protocol="HTTP/1.1" connectionTimeout="30000"/>
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="" workDir="temp">
<Context path="" docBase="www">
<Resource name="jdbc/MySQL" auth="Container" type="javax.sql.DataSource" username="server" password="server" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1:3306/common" maxActive="15" maxIdle="3"/>
</Context>
</Host>
</Engine>
</Service>
</Server>

这是 web.xml 文件中的内容:

<web-app>
<servlet><servlet-name>default</servlet-name><servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param><param-name>debug</param-name><param-value>0</param-value></init-param>
<init-param><param-name>listings</param-name><param-value>false</param-value></init-param>
</servlet>
<servlet><servlet-name>jsp</servlet-name><servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param><param-name>fork</param-name><param-value>false</param-value></init-param>
<init-param><param-name>xpoweredBy</param-name><param-value>false</param-value></init-param>
</servlet>
<servlet-mapping><servlet-name>default</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping><servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<session-config><session-timeout>30</session-timeout></session-config>
<mime-mapping><mime-type>image/png</mime-type>
<extension>png</extension>
</mime-mapping>
<mime-mapping><mime-type>text/html</mime-type>
<extension>htm</extension>
</mime-mapping>
<mime-mapping><mime-type>text/css</mime-type>
<extension>css</extension>
</mime-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
<Context>
<ResourceLink name="jdbc/MySQL" global="jdbc/MySQL" type="javax.sql.DataSource"/>
</Context>
</web-app>

最佳答案

看起来像是类路径问题。

您的 mysql-connector-java-*.jar 应该在您的 $CATALINA_HOME/lib 文件夹中。寻找“MySQL DBCP Example" in the official How-To:

在你的 CLASSPATH 变量中声明你的 mysql jdbc jar 文件,如下所示:
SET CLASSPATH=c:\mysql\mysql-connector-java-3.0.8-stable-bin.jar;

如果它不起作用,请提供您正在学习的教程以及您的配置文件在哪里。

关于java - 基本直接的 Tomcat-MySQL 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22358577/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com