2

I want to execute the same query on different database based on the request mapping url in controller .

Below is code snippet from my service impl class.

@Service("metricsService")
public class MetricsServiceImpl implements MetricsService {
    
    @PersistenceContext
    private EntityManager entityManager;
    
   String sql_query = "Select count(*) from user_details";

    public int countWPReqRaisedWithinDateRange(Date fromDate,Date toDate) {
        Query query = entityManager.createNativeQuery(sql_query);
        query.setParameter("fromDate", fromDate);
        query.setParameter("toDate",toDate);
        int count = ((Number) query.getSingleResult()).intValue();
        return count;
    }

}

I want to execute the same sql_query on different database based on the request mapping url.How can i customise this injected entity manager to execute on different database??

4

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.