Fionageo80
asked on
How to execute SQL statements from txt file using Hibernate
Hello,
I have a program, the user load a txt file that contain a list of SQL statements. I would like to know how can execute these SQL statements using Hibernate taking as a starting point that the user will load a list of Conventional SQL statements.
How can I do that?
Thank you for help.
I have a program, the user load a txt file that contain a list of SQL statements. I would like to know how can execute these SQL statements using Hibernate taking as a starting point that the user will load a list of Conventional SQL statements.
How can I do that?
Thank you for help.
ASKER
Thank you for your quick reply.
Actually I have to use Hibernate.
The SQL statements are listed as you can see below, one statement after the other.
I have a EntityBean.java that gets the EntityManager.
**** I want to know if I can execute directly these statements using entityManager.createNative Query? or createQuery? *****
Yes, I have to post process the result of those queries.
Thank you!
Actually I have to use Hibernate.
The SQL statements are listed as you can see below, one statement after the other.
I have a EntityBean.java that gets the EntityManager.
**** I want to know if I can execute directly these statements using entityManager.createNative
Yes, I have to post process the result of those queries.
Thank you!
select * from user a where status= 1 and not exists(select * from detail where id= a.id)
select * from user a where status <> 1 and exists(select * from detail where id= a.id)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The following code is assuming there is one SQL command per line (i.e. there is a newline character between each command) and that these are not query statement for which the program should analyze the result.
Note that in this example the session is closed after all the commands, but you can close it and open a new one after each command.
Open in new window