0

In a dao class implementation,I want to use different sql query depending upon the underlying database. Since my SQL query is complex which selects from a database view and uses "UNION" key word and uses database specific functions, I can not use JPQL (or HQL). I did some search on Stackoverflow and threads suggest the good way would be to find out the dialect used in the application. Can anyone provide some code example? EDIT : My apologies, I did not explain my question well enough. In my dao class implementation , I want to determine the database ( say mysql or oracle) on which my application is running and then execute the appropriate query. I need the code like jdbcTemplate.findOutTheDialect().

Amit Parashar
  • 1,447
  • 12
  • 15

2 Answers2

0

JPA have the native queries for that. An example you can find here.

Community
  • 1
  • 1
V G
  • 18,822
  • 6
  • 51
  • 89
0

You can use spring JdbcTemplate to connect and query from your database. For Example..

String query = "SELECT COUNTRY_NAME FROM COUNTRY WHERE MCC_COUNTRY NOT IN ('Reserved') ORDER BY COUNTRY_NAME";
jdbcTemplate.query(query, new ObjectRowMapper());

Where "ObjectRowMapper" will be a class to map return resultset to list of Objects.