java - How to configure Tomcat to connect with MySQL -
could provide few details on how configure tomcat access mysql?
in directory within tomcat place
mysql-connector-java-5.1.13-bin
? should place undertomcat 6.0\webapps\myapp\web-inf\lib
?do need add configuration
context.xml
orserver.xml
?should create
web.xml
file , place undertomcat 6.0\webapps\myapp\web-inf
? if so, should contents of file like?
1: place
mysql-connector-java-5.1.13-bin
in tomcat directory? should place undertomcat 6.0\webapps\myapp\web-inf\lib
?
that depends on connections managed. create connection pooled jndi datasource improve connecting performance. in case, tomcat managing connections , need have access jdbc driver. should drop jar file in tomcat/lib
.
but if you're doing basic way using drivermanager#getconnection()
, in fact don't matter if drop in tomcat/lib
or yourapp/web-inf/lib
. need realize 1 in tomcat/lib
apply all deployed webapps , 1 in yourapp/web-inf/lib
override 1 in tomcat/lib
particular webapp.
2: need confirgure
context.xml
orserver.xml
files?
that depends on connections managed. when using jndi datasource, suffices configure using yourapp/meta-inf/context.xml
follows (just create file if not exist):
<?xml version="1.0" encoding="utf-8"?> <context> <resource name="jdbc/yourdb" type="javax.sql.datasource" maxactive="100" maxidle="30" maxwait="10000" url="jdbc:mysql://localhost:3306/yourdb" driverclassname="com.mysql.jdbc.driver" username="yourname" password="yourpass" /> </context>
and yourapp/web-inf/web.xml
follows:
<resource-env-ref> <resource-env-ref-name>jdbc/yourdb</resource-env-ref-name> <resource-env-ref-type>javax.sql.datasource</resource-env-ref-type> </resource-env-ref>
if you're doing basic drivermanager
way, it's you. hardcoded, properties file, xml file, etcetera. should manage youself. tomcat won't (and can't) useful you.
noted should yourapp/meta-inf/context.xml
specific tomcat , clones. each servletcontainer/appserver has own way of defining jndi resources. in glassfish example, you'd through webbased admin interface.
3: should write
web.xml
file , need place undertomcat 6.0\webapps\myapp\web-inf
? if yes, should contents of file?
you should supply one. it's not configure resources, define servlets, filters, listeners , kind of mandatory stuff run webapp. file part of standard servlet api.
Comments
Post a Comment