How to read . sql file with Java

Asked

Viewed 499 times

0

I have a complex query in Mysql with sub-select and joins.

I would like to read this script through a file .sql using the language of JPA/Hibernate (JPQL or HQL), for example getSession().createQuery(arquivo.sql);.

Or another way that allows me to read the document to be failed in the repository. This is possible?

1 answer

0

String sqlString = path_to_file;
String sql = IOUtils.toString(new FileInputStream(sqlString), "UTF-8");
getSession().createSQLQuery(sql);

I took it and applied it Tranformers hibernate to process the information and turn it into a Dto.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.