How to execute sql directly in Hibernate?


General J2EE: How to execute sql directly in Hibernate?

  1. How to execute sql directly in Hibernate? (3 messages)

    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!

    Threaded Messages (3)

  2. How to execute sql directly in Hibernate?[ Go to top ]

    I hope this helps you.
     Configuration cfg = new Configuration();
     SessionFactory sf=cfg.buildSessionFactory();
     Session sess=sf.openSession();
     Statement st=sess.connection().createStatement();
     String sql="select * from foo";
  3. Thks[ Go to top ]

    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. :-)
  4. Hibernate Native SQL Example[ Go to top ]

    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 Hope this will help you. Deepak Kumar