Why is a Tomcat website showing database connection errors?

If a Tomcat website suddenly starts showing database connection errors, the problem is usually not Tomcat itself. In most hosted Java environments, the error points to a mismatch between the application, the JDBC configuration, and the MySQL service it is trying to reach. The website may still load static pages, but any page or servlet that queries the database can fail with messages such as Cannot create PoolableConnectionFactory, Communications link failure, Access denied for user, or Too many connections.

In a managed hosting setup with Plesk and a private Tomcat / JVM instance, the best way to troubleshoot is to check the database credentials, host name, port, user privileges, Java driver, and the application logs in that order. Most connection errors are caused by one of a few common issues, and they can usually be resolved without reinstalling the application.

What a Tomcat database connection error usually means

Tomcat does not store application data by itself. It connects your Java application to MySQL through a JDBC driver and a configured datasource or connection string. When that connection fails, the application cannot read or save data, and Tomcat returns an error from the app layer.

Common symptoms include:

  • Login pages failing to authenticate users
  • Blank pages where data should appear
  • HTTP 500 errors on database-backed pages
  • Connection pool warnings in catalina logs
  • JDBC timeout errors after a period of inactivity

On hosted platforms, the database may be local to the account, on a shared MySQL service, or on an external host. The exact fix depends on how the application is configured in Plesk, within My App Server, or inside the Tomcat deployment package.

Most common causes of MySQL connection errors in Tomcat

Incorrect database credentials

The most frequent cause is a wrong database username or password in the application configuration. This can happen after a password reset in Plesk, after importing a site, or after copying an app from another environment. If Tomcat is still using old credentials, the connection will be refused.

Wrong database host name or port

Many hosted applications are configured for localhost, but some hosting setups require a specific MySQL host name, socket path, or network address. If the database runs on a separate service, the app must use the correct host and port, usually 3306 for MySQL.

Missing JDBC driver

Tomcat needs a compatible MySQL JDBC driver. If the driver JAR is missing, outdated, or incompatible with the Java version in use, the application may fail as soon as it tries to open a connection.

Database user does not have enough privileges

The MySQL user may be able to log in but still not have permission to select, insert, update, or create the tables the application needs. This often appears after a restore, migration, or manual database creation.

Database server is unavailable or overloaded

If MySQL is down, restarting, under heavy load, or hitting connection limits, Tomcat cannot establish a new session. In shared hosting this may also happen when the application opens too many simultaneous connections.

Connection pool settings are too strict or too loose

Tomcat applications often use a pool to reuse database connections. If the pool is configured with a low max size, short timeout, or stale connection validation rules, the app may fail even when MySQL is healthy.

Java version and driver mismatch

A newer Java runtime or older JDBC driver combination can cause SSL, authentication, or protocol issues. This is especially relevant when the application was built on one Java version and deployed on a different one through My App Server.

Firewall or network restrictions

If the application connects to an external database, network rules can block the connection. This includes firewall restrictions, blocked IPs, or a database server that only accepts connections from approved hosts.

How to check the error in Tomcat logs

The first place to look is the application log and Tomcat log files. In a Plesk-based hosting environment, you can usually access these through the control panel or the file manager for the subscription.

Useful log locations may include:

  • catalina.out
  • localhost.log
  • Application-specific log files
  • Framework logs for Spring, Hibernate, or custom data layers

Look for the exact exception text. Different messages usually point to different causes:

  • Access denied for user — username, password, or privileges are wrong
  • Communications link failure — network, host, port, or MySQL service issue
  • Too many connections — database connection limit reached
  • Unknown database — database name is incorrect or missing
  • Public Key Retrieval is not allowed — JDBC driver or authentication setting mismatch

If the error is repeated only when the application becomes busy, the issue is likely related to pool configuration or database capacity rather than a simple login mistake.

Step-by-step troubleshooting checklist

1. Confirm the database is online

Open the database management area in Plesk or your hosting control panel and confirm that the MySQL service is available. If you have shell or service access in your hosting environment, check whether the database daemon is running.

If the database itself is unavailable, Tomcat cannot fix the issue. In that case, the problem is at the database service level and must be restored first.

2. Verify the database name, user, and password

Compare the values in the application configuration with the values shown in the hosting control panel. Common places to check include:

  • JDBC configuration files
  • Environment variables
  • Context descriptors
  • Spring or Hibernate properties
  • WAR file configuration bundled with the app

If the password was recently changed in Plesk, update the application immediately and redeploy or restart Tomcat so it loads the new settings.

3. Check the database host and port

Make sure the application is connecting to the correct MySQL host. For hosted apps this is often one of the following:

  • localhost
  • 127.0.0.1
  • A database service name provided by the hosting platform
  • An external IP or hostname

Also confirm the port. If the app points to the wrong port, the connection may time out even though MySQL is running normally.

4. Confirm that the JDBC driver matches your Java version

When using My App Server to run a private JVM with Tomcat, the Java version matters. A driver that worked on an older Java release may not behave the same way on a newer one. Make sure the MySQL Connector/J version is compatible with the Java runtime you selected during installation.

If the application was migrated from another platform, replace the bundled driver with a current version that matches the app and runtime combination.

5. Test the database login outside the application

Use the hosting control panel or a database client to log in with the same username and password. If the login fails there too, the issue is not Tomcat. It is either the credentials, privileges, or account-level database access.

If the login works externally but fails in Tomcat, focus on the application configuration and driver settings.

6. Review table permissions and schema ownership

After importing a site or restoring a backup, the database user may not own all required tables or may not have the correct access level. Ensure the application user has rights to the schema it uses.

This is especially important for applications that create tables during startup or during the first run. Missing CREATE or ALTER permission can prevent initialisation.

7. Restart the app server after configuration changes

Tomcat often caches connection pool settings and loaded classes. After editing datasource settings or replacing the JDBC driver, restart the service from the My App Server control options in Plesk so the new configuration is loaded cleanly.

In many cases, a restart is required for:

  • New JDBC driver JAR files
  • Updated database credentials
  • Changed pool settings
  • New environment variables
  • Updated Java version settings

8. Check for connection pool exhaustion

If the application works at low traffic but fails when more users arrive, the datasource pool may be exhausted. This can happen when connections are not closed properly in code or when the maximum pool size is too low for the workload.

Typical signs include slow page loads, growing numbers of waiting threads, and messages about timeouts or unavailable connections. In a hosted environment, it is wise to keep the pool size reasonable and make sure the application closes connections after each use.

9. Look for stale or timed-out connections

If the site works after a restart but fails later, the app may be reusing dead database connections. This can happen after MySQL restarts or after a network interruption. Enable connection validation if your application supports it, and set sensible timeouts so old connections are discarded before use.

Tomcat-specific settings that can affect database access

In a managed Tomcat hosting setup, the application is often deployed as a WAR file and may use a datasource defined in a context file or application properties. A few settings are worth checking carefully.

Datasource URL

The JDBC URL must match the database type, host, port, and schema. Even a small typo can break the connection. Examples of common issues include wrong schema name, missing SSL parameters, or a hostname copied from another environment.

Resource name and JNDI binding

If the application uses JNDI, make sure the datasource name in the app matches the resource name configured for Tomcat. A mismatch can produce lookup errors even when the database itself is healthy.

Connection timeout and max pool size

Too low a timeout can cause unnecessary failures. Too small a pool may create bottlenecks under traffic. In hosted Java environments, the right balance depends on application size and resource limits.

Driver class name

For MySQL, the class name is often com.mysql.cj.jdbc.Driver in modern setups. Older applications may use a deprecated class name. If the app was written long ago, review whether it still uses an outdated driver reference.

What to do if you use My App Server in Plesk

With My App Server, you can manage a private Tomcat and JVM inside your hosting account. That gives you useful control, but it also means the application depends on the configuration stored in your account and in the Plesk extension.

When troubleshooting database errors in this environment:

  • Confirm the selected Java version is appropriate for the app and driver
  • Verify that the Tomcat service is running
  • Check whether the app was redeployed after changing database settings
  • Make sure the correct WAR or application directory is active
  • Review logs inside the My App Server or Plesk-managed app directory

If you uploaded a custom application server or custom Tomcat build, confirm that the MySQL driver is available in the runtime classpath. A missing dependency can be masked during startup and only appear when the first database request is processed.

Typical error messages and what they usually mean

Access denied for user

This usually means the username, password, or host permission is wrong. Check the exact database account details in the control panel and verify that the application is using the same values.

Communications link failure

This usually points to a network problem, wrong host name, wrong port, or MySQL not responding. It can also happen if the connection is dropped due to idle timeout.

Unknown database

The database name in the app does not exist, was deleted, or was typed incorrectly. Make sure the schema exists and that the app points to the right one.

Too many connections

MySQL has reached its open connection limit. This may be caused by too many simultaneous users, a connection leak in the code, or a pool that opens too many sessions at once.

No suitable driver

Tomcat cannot find the JDBC driver or the driver class is wrong. Check the driver JAR placement and the configured class name.

Best practices to prevent future connection errors

  • Keep database credentials documented and updated in one place
  • Use a JDBC driver version compatible with both Java and MySQL
  • Restart Tomcat after changing datasource or driver settings
  • Monitor logs for repeated timeout or pool warnings
  • Use reasonable connection pool sizes for shared hosting resources
  • Close connections properly in application code
  • Test database access after deployments and migrations
  • Prefer stable configuration files over hidden or duplicated settings

For hosted Java applications, it is also a good idea to keep the app structure simple. A small or medium Tomcat application with a private JVM, clear datasource settings, and a single database schema is easier to support than a heavily customised deployment with multiple layers of indirection.

When the problem is not in Tomcat

Sometimes the website error looks like a Tomcat issue, but the real cause is outside the app server. Examples include:

  • A MySQL service outage
  • A database account locked or disabled in the control panel
  • A password changed without updating the app
  • An expired or moved database backup
  • Firewall rules blocking a remote database host
  • A disk space issue preventing MySQL from writing data

If you have already checked the application configuration and the logs still point to a service-level problem, collect the exact error text, timestamp, and recent changes before contacting support. This helps identify whether the issue is related to the database service, the Java runtime, or the Tomcat deployment.

FAQ

Why does the site work on some pages but not on others?

Pages that do not need the database may load normally, while pages that query MySQL fail. This is a strong sign that the connection problem is limited to database-backed functionality.

Can a Tomcat restart fix database errors?

Sometimes, yes. A restart can clear stale connections, reload the JDBC driver, and apply updated settings. However, it will not fix wrong credentials, missing permissions, or a down database server.

Should I use localhost for the MySQL host?

Only if your hosting setup uses a local MySQL service for the same account or server. In some managed environments, the correct value is different. Always use the host name provided by the control panel or hosting documentation.

Do I need a special driver for newer Java versions?

Often yes. The MySQL Connector/J version should match the Java runtime and the database authentication method. If you switch Java versions in My App Server, review the driver compatibility too.

Why do connection errors appear after a period of inactivity?

This usually means the pool is reusing a connection that the database has already closed. Adjust validation and timeout settings so Tomcat checks the connection before using it.

Can I fix this from Plesk?

Many causes can be fixed from Plesk, including updating database credentials, checking database availability, redeploying the app, and restarting the Tomcat service through My App Server.

Conclusion

When a Tomcat website shows database connection errors, the root cause is usually one of a small number of issues: incorrect MySQL credentials, wrong host or port, missing JDBC driver, insufficient permissions, pool exhaustion, or a MySQL service problem. In a hosting environment with Plesk and My App Server, the most effective approach is to check the database settings, review the Tomcat logs, confirm driver compatibility with the selected Java version, and restart the service after any change.

By working through the connection details methodically, you can usually restore the application quickly and avoid unnecessary changes to the deployment. For Java, JSP, servlet, and Tomcat hosting, clean configuration and consistent database settings are the key to stable operation.

  • 0 Users Found This Useful
Was this answer helpful?