Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. package javaapplication4;
  8.  
  9. import javax.transaction.Transaction;
  10. import org.hibernate.Session;
  11. import org.hibernate.SessionFactory;
  12. import org.hibernate.cfg.Configuration;
  13.  
  14.  
  15.  
  16. /**
  17.  *
  18.  * @author student
  19.  */
  20. public class JavaApplication4 {
  21.  
  22.    
  23.     public static void main(String[] args) {
  24.        
  25.        
  26.      
  27.        
  28.         Configuration configuration = new Configuration().      
  29.     setProperty("connection.driver_class","com.mysql.jdbc.Driver").
  30.     setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/hibernate").          
  31.      setProperty("hibernate.connection.username", "root").    
  32.     setProperty("hibernate.connection.password", "").
  33.     setProperty("dialect", "org.hibernate.dialect.MySQLDialect").
  34.     setProperty("hibernate.hbm2ddl.auto", "update").
  35.     addAnnotatedClass(Student.class);
  36.         SessionFactory factory = configuration.buildSessionFactory();
  37.         Session session = factory.openSession();
  38.         org.hibernate.Transaction transaction = session.beginTransaction();
  39.        
  40.          Student student1= new Student ("Adam", "Kosa", 1234);
  41.         Student student2= new Student ("Kamil", "Sawes", 1233);
  42.         Student student3 = new Student();
  43.        
  44.         session.save(student1);
  45.         session.save(student2);
  46.         session.save(student3);
  47.         transaction.commit();
  48.        
  49.        
  50.         session.close();
  51.         factory.close();
  52.        
  53.        
  54.    
  55.  
  56.     }
  57.    
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement