...
2. Copy the PostgreSQL JDBC Driver to Tomcat
(if the application is about to be deployed on Heroku, this step is not needed)
- Download the PostgreSQL driver (v9.4) from PostgreSQL official site.
- Add the PostgreSQL driver jar (postgresql-9.4.1208.jre6.jar) to
<tomcat-install>/lib/
directory.
3. Configure a DataSource for TermWeb in Tomcat
(if the application is about to be deployed on Heroku, this step is not needed)
Edit
<tomcat-install>/conf/context.xml
.Within the
Context
tags, insert the DataSourceResource
tag:Code Block language xml <Resource name="jdbc/TermWebDS" auth="Container" type="javax.sql.DataSource" username="termwebuser" password="termwebpwd" driverClassName="org.postgresql.Driver" url="jdbc:postgresql://localhost/termweb" maxActive="20" maxIdle="10" validationQuery="Select 1"/>
- If PostgreSQL does not run on the same server as Tomcat, replace
localhost
in url with the name of the database server - If you named the database something else than
termwebdb
, replacetermwebdb
in url with your database name - Replace
termwebuser
andtermwebpwd
in url with your database user and password.
- If PostgreSQL does not run on the same server as Tomcat, replace
The configuration properties for Tomcat's standard data source resource factory (
org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory
) are as follows:driverClassName
– Fully qualified Java class name of the JDBC driver to be used.maxActive
– The maximum number of active instances that can be allocated from this pool at the same time.maxIdle
– The maximum number of connections that can sit idle in this pool at the same time.maxWait
– The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception.password
– Database password to be passed to our JDBC driver.url
– Connection URL to be passed to our JDBC driver. (For backwards compatibility, the property driverName is also recognized.)user
– Database username to be passed to our JDBC driver.validationQuery
– SQL query that can be used by the pool to validate connections before they are returned to the application. If specified, this query must be an SQL SELECT statement that returns at least one row.
...