Hi Sindhu,
Completed tasks can be viewed from History in the camunda cockpit. This feature is available only for enterprise customers. So for community users you can always view only runtime data.
You can query the db with processInstanceId in history tables or you can access either using Java API/Rest API.
To query service tasks and events (history): Get Historic Activity Instances | docs.camunda.org
To query user tasks (history): Get Tasks (Historic) | docs.camunda.org
To query process instance (history): Get Process Instances | docs.camunda.org
To query service tasks and events (history):
HistoricActivityInstance historicActivityInstance = execution
.getProcessEngineServices()
.getHistoryService().createHistoricActivityInstanceQuery()
.processInstanceId("processInstanceId").singleResult();
To query user tasks (history):
HistoricTaskInstance historicTaskInstance = execution
.getProcessEngineServices().getHistoryService()
.createHistoricTaskInstanceQuery().processInstanceId("processInstanceId")
.singleResult();
To query process instance (history):
HistoricProcessInstance historicProcessInstance = execution.getProcessEngineServices()
.getHistoryService().createHistoricProcessInstanceQuery()
.processInstanceId("processInstanceId").singleResult();
For DB queries, check this post: