Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
350 views
in Technique[技术] by (71.8m points)

eclipse - how to connect tomcat 7 and mysql

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...