Skip to content

Instantly share code, notes, and snippets.

@dylants
Created August 22, 2013 20:56
Show Gist options
  • Save dylants/6312697 to your computer and use it in GitHub Desktop.
Save dylants/6312697 to your computer and use it in GitHub Desktop.
Context.xml to be defined within a Java web application, under src/main/webapp/META-INF. This defines the database connection using JDBC within Tomcat. Defining this within the context.xml will configure the container, and allow the Java web app to connect via JNDI. This can also be included in the Tomcat server.xml, keeping configuration outsid…
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE project>
<Context>
<Resource name="jdbc/web"
auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
testWhileIdle="true"
testOnBorrow="true"
testOnReturn="false"
validationQuery="SELECT 1"
timeBetweenEvictionRunsMillis="30000"
maxActive="15"
maxIdle="10"
minIdle="5"
removeAbandonedTimeout="60"
removeAbandoned="false"
logAbandoned="true"
minEvictableIdleTimeMillis="30000"
jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
username="root"
password="password"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/book-admin"/>
</Context>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment