Hi everyone:
I want to execute SQL script using Hibernate.So I want to know whether hibernate can do it.For example: I read some sql statement from a config file . And I want to execute them but don't use JDBC!
Could hibernate do it? THks!
-
How to execute sql directly in Hibernate? (3 messages)
- Posted by: lyo Yashnoo
- Posted on: September 09 2004 00:45 EDT
Threaded Messages (3)
- How to execute sql directly in Hibernate? by danel danel on September 09 2004 09:39 EDT
- Thks by lyo Yashnoo on September 14 2004 00:49 EDT
- Hibernate Native SQL Example by Deepak Kumar on August 06 2006 07:44 EDT
-
How to execute sql directly in Hibernate?[ Go to top ]
- Posted by: danel danel
- Posted on: September 09 2004 09:39 EDT
- in response to lyo Yashnoo
I hope this helps you.
Configuration cfg = new Configuration();
cfg.configure("hibernate.cfg.xml");
SessionFactory sf=cfg.buildSessionFactory();
Session sess=sf.openSession();
Statement st=sess.connection().createStatement();
String sql="select * from foo";
st.executeQuery(sql); -
Thks[ Go to top ]
- Posted by: lyo Yashnoo
- Posted on: September 14 2004 00:49 EDT
- in response to danel danel
You mean that Hibernate don't supply the query session interface. I must create my own connection and execute JDBC code. THank you.I will try it. :-) -
Hibernate Native SQL Example[ Go to top ]
- Posted by: Deepak Kumar
- Posted on: August 06 2006 07:44 EDT
- in response to danel danel
Hi, Native SQL is handwritten SQL for all database operations like create, update, delete and select. Hibernate Native Query also support stored procedures. In this example you will be creating Hibernate Application to run your native query to calculate the average of invested amount from the insurance table. In the second example you will write Hibernate Native Query Example to retrieve all the entities from insurance table. Have a look at http://www.roseindia.net/hibernate/hibernate-native-sql.shtml Hope this will help you. Deepak Kumar