JDBC Setup and Pooling Strategy

Modern drivers, proper pooling, connections that don't go stale

Configure ColdFusion 2025 datasources with modern JDBC drivers, proper connection pooling, and fail-fast validation to ensure reliable database connectivity.

Use Modern JDBC Drivers

You should always prefer vendor-provided JDBC drivers over legacy bridges for better performance and security:

  • Do not use: MS Access, ODBC-JDBC bridges, or DB2 legacy stacks
  • Do use: Latest vendor JDBC drivers directly
  • Download drivers from official vendor sites
  • Place JAR files in {cf_root}/cfusion/lib (server configuration) so they are on the ColdFusion classpath
  • Restart ColdFusion after adding drivers

Popular Database Drivers

Popular Database Drivers
Driver Class: com.mysql.cj.jdbc.Driver
JDBC URL: jdbc:mysql://hostname:3306/database?sslMode=REQUIRED
Validation Query: SELECT 1
Driver Class: org.postgresql.Driver
JDBC URL: jdbc:postgresql://hostname:5432/database
Validation Query: SELECT 1
Driver Class: com.microsoft.sqlserver.jdbc.SQLServerDriver
JDBC URL: jdbc:sqlserver://hostname:1433;databaseName=mydb;encrypt=true
Validation Query: SELECT 1
Driver Class: oracle.jdbc.OracleDriver
JDBC URL: jdbc:oracle:thin:@hostname:1521:SID
Validation Query: SELECT 1 FROM DUAL

Connection Pool Configuration

Configure connection pooling for optimal performance and resource usage using the CF Administrator Data Sources page:

  • Max Connections: Set the pool size to database CPU cores × 2 as a starting point
  • Login Timeout (sec): Set how long ColdFusion waits to establish a connection (5-10 seconds is a reasonable start)
  • Timeout (min): Number of minutes ColdFusion keeps an unused connection open
  • Maintain Connections: Keep connections open in the pool between requests
  • Validation: Where your driver's advanced settings offer it, check Enable connection validation and supply a validation query. The query runs when a pooled connection is reused; Adobe notes it adds an extra query, so weigh the overhead (Source: Adobe: Data Source Management)
  • Query Timeout (sec): Where your driver's advanced settings offer it, stop runaway queries from holding connections
Connection Pool Configuration Example
# ColdFusion Administrator > Data Sources > (datasource) > Show Advanced Settings
Limit Connections: checked
Restrict connections to: 50
Maintain Connections: checked
Timeout (min): 20
Login Timeout (sec): 10
Query Timeout (sec): 30
Enable connection validation: checked
Validation Query: SELECT 1

Security Best Practices

  • Store credentials in external secrets manager (not in Administrator)
  • Use encrypted connections (SSL/TLS) to database
  • Create dedicated database user per application
  • Grant minimum required permissions
  • Use read-only datasources for reporting queries
  • Never use sa or root accounts

Read/Write Splitting

For databases with replication enabled, you should configure separate datasources for read and write operations:

  • Write Datasource: Configure this datasource to point to the primary/master database
  • Read Datasource: Configure this datasource to point to the replica/slave database
  • Use the write datasource for all INSERT, UPDATE, and DELETE operations
  • Use the read datasource for SELECT queries to improve performance
  • This strategy reduces load on the primary database and improves overall scalability

Connection Leaks

cfquery and queryExecute() return connections to the ColdFusion pool automatically, so you don't close them yourself. The Administrator has no abandoned-connection or leak-detection settings. If the pool runs dry, look for long-running queries (set a Query Timeout) and watch datasource metrics in PMT.

Best Practice: Explicit close and finally handling only matters when you use raw JDBC objects through createObject("java").

Performance Optimization

  • Use cfqueryparam for all SQL parameters (security + performance)
  • Enable query caching for expensive, frequently-run queries
  • Avoid ORM N+1 queries with join or batch fetching (fetch="join" or batchsize) where related data is always needed; use lazy loading to skip data you don't need
  • Index database columns used in WHERE clauses
  • Monitor slow queries with PMT
  • Consider database connection pooling at load balancer level

Datasource Checklist

  • Latest vendor JDBC driver installed
  • Connection validation query configured
  • Max connections sized appropriately
  • Login timeout set (5-10 seconds)
  • Query timeout set for long-running queries
  • SSL/TLS encryption enabled
  • Credentials stored in secrets manager
  • Minimum privilege database user
  • cfqueryparam used for all parameters

Gotchas

  • Too many max connections can overwhelm database - start conservative
  • JDBC drivers must match database version - update regularly
  • Connection validation adds overhead - balance security vs performance
  • Legacy ODBC bridges cause performance and stability issues
  • Database firewall timeouts must exceed ColdFusion connection timeout

Need Help?

Convective can help optimize database connectivity and troubleshoot connection issues.

Find out more
ColdFusion Datasources and JDBC Configuration - Database Connection Guide | CFGuide