如何连接tomcat 7和mysql [英] how to connect tomcat 7 and mysql

查看:93
本文介绍了如何连接tomcat 7和mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

im相当新的j2ee .....
i刚刚完成阅读头第一个servlets和jsp ....



为一个练习项目我是想要构建一个钱追踪器,我可以在其中节省我的费用,并在以后随时看到它们。
但是为此我需要一个数据库,我googled为它,发现mysql是一个很好的数据库,但我不知道如何设置tomcat与mysql进行交谈....



和im使用eclipse开普勒与tomcat 7 .......



plz告诉我配置tomcat的步骤是什么,以便它可以看到mysql,我可以通过我的代码访问数据库......



im on windows 8。



似乎设置的东西比编码更困难
plz plz plz帮助我


解决方案

这些是您可以做的一些步骤:


  1. 创建一个context.xml并将其保存在TOMCAT_HOME / conf下。


  2. 添加您的数据库配置可能如下所示:



    <资源名称=jdbc / testauth =容器type =javax .sql.DataSource
    maxActive =510minIdle =0maxIdle =200maxWait =10000
    username =testpassword =testdriverClassName =com.mysql。 jdbc.Driver
    url =jdbc:mysql://127.0.0.1:3306 / test
    poolPreparedStatements =truemaxOpenPreparedStatements =510
    validationQuery =SELECT 1testOnBorrow =true
    />


  3. 在应用程序的web.xml中参考上述上下文,如:



    < resource-ref>
    < description> DB连接< / description>
    < res-ref-name> jdbc / test< / res-ref-name>
    < res-type> javax.sql.DataSource< / res-type>
    < res-auth>容器< / res-auth>
    < / resource-ref>


  4. 放JAR(例如mysql-connector-java-5.1.12 -bin.jar)包含mysql驱动程序到TOMCAT_HOME / lib


我希望它会有所帮助。

i m quite new to j2ee..... i just finished reading head first servlets and jsp ....

for a practice project i was thinking to build a money tracker in which i can save my expenses and see them anytime in the future.... but for this i need a database , i googled for it and found that mysql is a good database but i know nothing about how to set tomcat to talk to mysql....

and i m using eclipse kepler with tomcat 7 .......

plz tell me what are the steps to follow to configure tomcat so that it can see mysql and i can access the database through my codes ......

i m on windows 8.

it seems like setting up things is more difficult than coding plz plz plz help me

解决方案

These are some steps you could do:

  1. Create a context.xml and save it under TOMCAT_HOME/conf.

  2. Into the context.xml you have to add your DB configuration which could look like:

    <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" />

  3. In the web.xml of your application refer to the above context, like:

    <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>

  4. Put the JAR (e.g. mysql-connector-java-5.1.12-bin.jar) containing the mysql driver into TOMCAT_HOME/lib

I hope it will help.

这篇关于如何连接tomcat 7和mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆