Fixed the database lock error by adding in a try catch into the first try catch statement. Statements and Connections must be closed if there is an error