A controller comprising: an instruction executing unit configured to execute a user program for controlling a controlled object; a communication interface configured to connect with a database system; an access processing unit configured to generate an instruction sentence in accordance with an access instruction for accessing the database system, in response to execution of the user program containing the access instruction, and to control an access to the database system on the basis of the generated instruction sentence; a status output unit configured to generate status information that indicates an execution status of the instruction sentence and to output the generated status information, from when the access processing unit starts a process of access to the database system on the basis of the instruction sentence generated in accordance with the access instruction to when the access processing unit completes the process based on the instruction sentence; and a holding unit configured to hold a recovery program that refers to the status information and that recovers the process of the access to the database system in case of a power interruption of the controller, the recovery program executing predefined measures depending on an access status indicated by the status information, and the recovery program being executed in a predetermined operating status, wherein the status information contains information that indicates a sending status of a SQL sentence for accessing the database system. an instruction executing unit configured to execute a user program for controlling a controlled object; a communication interface configured to connect with a database system; an access processing unit configured to generate an instruction sentence in accordance with an access instruction for accessing the database system, in response to execution of the user program containing the access instruction, and to control an access to the database system on the basis of the generated instruction sentence; a status output unit configured to generate status information that indicates an execution status of the instruction sentence and to output the generated status information, from when the access processing unit starts a process of access to the database system on the basis of the instruction sentence generated in accordance with the access instruction to when the access processing unit completes the process based on the instruction sentence; and an access processing unit configured to generate an instruction sentence in accordance with an access instruction for accessing the database system, in response to execution of the user program containing the access instruction, and to control an access to the database system on the basis of the generated instruction sentence; a status output unit configured to generate status information that indicates an execution status of the instruction sentence and to output the generated status information, from when the access processing unit starts a process of access to the database system on the basis of the instruction sentence generated in accordance with the access instruction to when the access processing unit completes the process based on the instruction sentence; and a holding unit configured to hold a recovery program that refers to the status information and that recovers the process of the access to the database system in case of a power interruption of the controller, the recovery program executing predefined measures depending on an access status indicated by the status information, and the recovery program being executed in a predetermined operating status, wherein the status information contains information that indicates a sending status of a SQL sentence for accessing the database system.