This page has been replaced by Configure application server based data sources and Data source configuration - problem determination. Some of the information is out of date with respect to new releases of the app. However, we have kept the page as it has comments and answers that may still be helpful.

Summary


SQL for Confluence uses data sources defined to the application server to gain access to the database. The data source is referenced using the dataSource parameter. The exact configuration of a data source is application server and database specific. The configuration must be done by a Confluence administrator and the Confluence application server must be restarted for changes to be active. The configuration must be done very carefully as any errors results in the data source being unusable (sad). Each database you need to access in Confluence must a have a data source configuration.

These are the major elements of the configuration:

  1. Application server data source configuration - consult your application server documentation on how this is done and problem determination mechanisms. Note that the configuration may be specific to the application server version. For example, older Tomcat versions have some different configurations.
  2. JDBC driver specific for the database to be accessed - consult your database documentation and other sources for the best JDBC driver to use.
  3. Installation of JDBC driver on the application server.
  4. Database access - consult your database documentation on how to configure your database for access.

Various users have provided some examples that cover many standard situations. This page can be used to share that type of information as well as problem determination information. This is the best place to start especially if you are not an expert in this area.



A common problem is errors after upgrading Confluence. Ensure that your upgrade procedures include updating your server.xml and copying all the JDBC drivers you use into the appropriate location. Also, check out this page for isolating these or application server version differences that cause problems. If you get errors immediately after an upgrade, this is the most likely cause.




Confluence standalone installation (Tomcat)

Many users install the standard Confluence standalone distribution. This section discusses configuration specific to this application server environment. The most recent versions of Confluence use newer versions of the Tomcat application server where the following configuration examples apply:

JDBC driver location

Put the driver jar in <install-dir>/lib - this is the directory that has other Tomcat jars. If you have an older version of Confluence that does not have this directory, look for <install-dir>/common/lib instead.

Tomcat configuration

Modify <install-dir>/conf/server.xml to add one or more data source resource elements. User's Guide is an example of adding a few data sources for various local and non-local databases.

The essential element is something like the following, where the data source name is myDS:

<Resource name="jdbc/myDS"
    auth="Container" 
    type="javax.sql.DataSource" 
    username="confluence" 
    password="confluence"
    maxActive="100"
    maxIdle="10"
    driverClassName="org.postgresql.Driver"
    url="jdbc:postgresql://localhost:5432/mydatabase"
    validationQuery="Select 1"
/>



...
<Context path="" docBase="../confluence" debug="0" reloadable="false">
...
<Resource ... />
...
</Context>



Database examples

The sql macro markup looks like: {sql:datasource=myDS| ... }

Database, Information, JDBC driver example, Resource configuration
PostgreSQL, [PostgreSQL JDBC|http://jdbc.postgresql.org/], postgresql-8.2-507.jdbc3.jar, "{noformat}
<Resource name=""jdbc/myDS""
    auth=""Container""
    type=""javax.sql.DataSource""
    username=""confluence""
    password=""confluence""
    maxActive=""100""
    maxIdle=""10""
    driverClassName=""org.postgresql.Driver""
    url=""jdbc:postgresql://localhost:5432/confluence""
    validationQuery=""Select 1""
/>{noformat}"
MySQL, [MySql connector|http://dev.mysql.com/downloads/connector/j/5.1.html], mysql-connector-java-3.1.14-bin.jar, "{noformat}
 <Resource name=""jdbc/myDS""
    auth=""Container""
    type=""javax.sql.DataSource""
    driverClassName=""com.mysql.jdbc.Driver""
    url=""jdbc:mysql://localhost/mydatabase?autoReconnect=true""
    username=""username""
    password=""password""
    maxActive=""25""
    maxIdle=""5""
    maxWait=""10000""
/> {noformat}\\ See SQL-146 for info on how to configure multiple result sets."
Oracle, Thin Driver\\ [Oracle JDBC|http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-111060-084321.html], ojdbc6.jar, "{noformat}
<Resource
    name=""jdbc/myDS""
    auth=""Container""
    type=""javax.sql.DataSource""
    driverClassName=""oracle.jdbc.OracleDriver""
    url=""jdbc:oracle:thin:@www.some_server.com:1521:mysid""
    username=""username""
    password=""password""
    connectionProperties=""SetBigStringTryClob=true""
    maxActive=""25""
    maxIdle=""5""
    maxWait=""10000""
/> {noformat}"
Oracle Advanced, Thin Driver \\ [Oracle JDBC|http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-111060-084321.html], ojdbc6.jar, See [Tomcat 6.0 using Oracle Universal Connection Pool|http://www.oracle.com/technetwork/articles/oem/ucp-jdbc-tomcat-355431.html]
Microsoft SQL Server, [jtds driver|http://jtds.sourceforge.net/], jtds-1.2.2.jar, "{noformat}
<Resource
    name=""jdbc/myDS""
    auth=""Container""
    type=""javax.sql.DataSource""
    driverClassName=""net.sourceforge.jtds.jdbc.Driver""
    url=""jdbc:jtds:sqlserver://mysqlserver:1433/mydatabase""
    username=""username""
    password=""password""
    maxActive=""20""
    maxIdle=""10""
    maxWait=""-1""
/> {noformat}"
Derby, [Derby|http://db.apache.org/derby/], derbyclient.jar, "{noformat}
<Resource
    name=""jdbc/myDS""
    auth=""Container""
    type=""javax.sql.DataSource""
    driverClassName=""org.apache.derby.jdbc.ClientDriver""
    url=""jdbc:derby://localhost:1527/dbname""
    username=""username""
    password=""password""
    maxActive=""20""
    maxIdle=""10""
/>{noformat}"

Other databases

Support for other databases depends on the capabilities provided by the JDBC driver. The SQL for Confluence expects certain JDBC features to be available. In some cases, parameter choices can affect which capabilities are needed. User testing and community support is about the only help that is available for less popular databases/JDBC drivers. If you have had success with other databases, please add information to this page.


WebLogic 9.1 application server

  1. In the WebLogic console, under Services > JDBC, create a data source (see WebLogic's documentation on how to Configure JDBC data sources for more information).
  2. Take note of the JNDI name you used to create the data source.
  3. Point the SQL macro to that JNDI name (dataSource parameter).

Problem determination

Here are some common errors and examples.

  1. Double check all the configuration values and that JDBC driver is installed - use the information above.
  2. Make sure you restarted Confluence after making configuration changes.
  3. Make sure your database is configured from remote access from the Confluence server with the user and password provided. If you have problems, connect using an independent SQL client from the server to verify access. Consult your database documentation for how to configure remote access and database permissions.

Error - no JDBC driver

Error - database server not found

Error - port

Error - user authentication

Error - validation query

Error - user authority

Error - bad server.xml configuration

Error - class not found

Error - Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)

Error - MyDS not found

Non-standard JDBC drivers

If you are using a non-standard JDBC driver for accessing less common databases, there are potential problems with unsupported or non-standard behavior. Experiment on a test instance to ensure it works as expected. Here are some workarounds for problems you might encounter. If you continue to have problems, you may need to debug the code on your installation.

  1. Hangs - SQL-86 is an example. Use multipleResults=false to disable multiple results sets.
  2. Avoid using horizontal rowOrientation.

Broken database connections - java.sql.SQLRecoverableException

Add a validation query to your configuration. This helps the application server connection pool to recover from database connection problems.

validationQuery="Select 1"

Other errors

For other errors related to connectivity, google your symptoms and application server combination.

SQL exceptions

Consult your database documentation as SQL has some database specific differences (sad). It is best to validate your SQL outside of Confluence before putting it on a page. Use a database admininstrator tools (pgAdmin for instance), some general SQL client, or various Eclipse database plugins.