我对 j2ee 很陌生..... 我刚刚读完 head first servlets and jsp ....
对于一个实践项目,我正在考虑构建一个金钱追踪器,我可以在其中节省我的开支并在未来随时查看它们...... 但为此我需要一个数据库,我在谷歌上搜索了一下,发现 mysql 是一个很好的数据库,但我对如何设置 tomcat 与 mysql 对话一无所知....
我正在使用带有 tomcat 7 的 eclipse kepler ......
请告诉我配置tomcat的步骤是什么,以便它可以看到mysql并且我可以通过我的代码访问数据库......
我在 Windows 8 上。
看起来设置东西比编码更难 plz plz plz 帮助我
最佳答案
这些是您可以执行的一些步骤:
创建一个 context.xml 并将其保存在 TOMCAT_HOME/conf 下。
在 context.xml 中,您必须添加您的数据库配置,如下所示:
<Resource name="jdbc/test" auth="Container" type="javax.sql.DataSource" maxActive="510" minIdle="0" maxIdle="200" maxWait="10000" username="test" password="test" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1:3306/test" poolPreparedStatements="true" maxOpenPreparedStatements="510" validationQuery="SELECT 1" testOnBorrow="true" />
在您的应用程序的 web.xml 中引用上述上下文,例如:
<resource-ref> <description>DB Connection</description> <res-ref-name>jdbc/test</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
将包含mysql驱动的JAR包(如mysql-connector-java-5.1.12-bin.jar)放入TOMCAT_HOME/lib
希望对您有所帮助。
关于mysql - 如何连接tomcat 7和mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27089414/