DBCp connection!

Posted: August 13, 2008 in Uncategorized

1.create your own context.xml file and put in Yourapp/META-INF/ location

its contents should be
<Context docBase=”Tracker” path=”/Tracker”>

<Resource name=”jdbc/tracker” scope=”Shareable” type=”javax.sql.DataSource”
factory=”org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory”
url=”jdbc:mysql://localhost:3306/tracker?autoReconnect=true”
driverClassName=”com.mysql.jdbc.Driver”
username=”root”
password=”admin”
maxIdle=”5″
maxActive=”50″

/>
2.Then make entry in web.xml
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/tracker</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

3.Then place mysql-connector-java-3.1.13.jar in TOMCAT_HOME/common/lib folder
4.place jstl.jar.standar,jar in TOMCAT_HOME/common/lib folder/

or

in you webInf/lib folder(this is optional stepp if u using jstl)

5. use any where with code
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup(“java:comp/env/jdbc/tracker”);
connection = ds.getConnection();

Note:

-download Connector/J 3.0.11-stable (the official JDBC Driver)

-Downlaod jstl lib(standard.jar, jstl.jar agian this is optional)

you can email me for jdbc connector and JStl lib at aijaza.b@gmail.com

for refrence also check that link

http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s