These instructions will help you connect TermWeb to a Microsoft SQL Server 2012 database.PostgreSQL database. Versions from 9.2 and above are supported.
1. Create and Configure the
...
PostgreSQL Database
- Create a database for TermWeb to store data in (e.g.
termweb
).- Open pgAdmin and right click on Databases and select New Database
Name: termweb
Encoding: UTF8
Template: template0
Collation: C
Character Type: C
- Open pgAdmin and right click on Databases and select New Database
- Create a database login role (user) which TermWeb will connect as (e.g.
termwebuser
), with permissions for the database.- Create a new login role (right click on Login Roles and select New Login Role) and name it termwebuser. Select password: termwebuser termwebpwd.
- Set login role as database owner and set permissions (right click on
termweb
database and select Properties). Select termwebuser as owner.
- Execute the
grant_privileges_postgresql.sql
file from the installation package to grant the necessary privileges to termwebuser. - Connect as the new user before creating TermWeb tables. This is important, in order for the new user to also be owner of every table.
- Right click on PostgreSQL server and select Disconnect server
- Right click on PostgreSQL server and select Properties
- Write termwebuser as username
- Doubleclick on PostgreSQL server to connect (might need to do it twice, due to wrong password)
- Write the password termwebpwd in order to connect with the new user
- Execute the
termweb_postgresql.sql
file from the installation package to create the database tables.- Select Select
termweb
database and click on on SQL icon icon to open an SQL execution window. - Copy paste termweb_postgresql.sql content and execute query.
- Select Select
After successfully creating the TermWeb schema on a PostgreSQL database, you need to pass the credentials of your database in the context of Tomcat by following steps 2 and 3.
However, if you are planning to deploy TermWeb on a Heroku container, the following steps are not needed. Instead you can directly follow this tutorial on how to deploy on Heroku.
The reason for this is that a Heroku container has an embedded Tomcat server, which does not use context properties. That is why we don't configure the data source in Tomcat.
TermWeb is configured to use Heroku's standard way of reading the data source, i.e. to get the database credentials from the container's environmental variables.
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 SQL Server JDBC PostgreSQL driver jar (jtdspostgresql-19.4.31208.1jre6.jar) to
<tomcat-install>/lib/
directory.
Make sure to download the correct version that is compatible with your Java version (e.g. jre7 for Java 1.7)
If you are using Tomcat 8, there are cases where you can totally skip this step.
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
net" username="termwebuser" password="termwebpwd" driverClassName="
sourceforgeorg.
jtds.jdbc.postgresql.
Driver"
jtds:sqlserverurl="jdbc:
termwebdb;user=termwebuser;password=termwebpwd;useLOBs=false"postgresql://localhost/
termweb" maxActive="20"
maxIdle="10"
validationQuery="Select 1"/>
- If
SQL Server - 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.
- 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.
Congratulations, you now have TermWeb connected to your SQL Server PostgreSQL database.