MSSQL Transaction Log Full

Problem: Occasionally I get the following JDBC error from MSSQL:

The log file for database 'db_example' is full. Back up the transaction log for the database to free up some log space.

Solution:

BACKUP LOG db_example WITH TRUNCATE_ONLY
DBCC SHRINKFILE(db_example_log, 2)

If ‘db_example_log’ is not the logical name of the logfile, the 2nd command will fail. The correct logical name can be found by running the following statements:

USE db_example;
SELECT * FROM sysfiles;