/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package roseindia;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

/**
 *
 * @author Administrator
 */
public class JPACreate { 
    
    public static void main(String arg[]){
        EntityManagerFactory emf=Persistence.createEntityManagerFactory("netjpa");
        EntityManager em=emf.createEntityManager();
        try{
            EntityTransaction entr=em.getTransaction();
            entr.begin();
            Student stu=new Student();
            stu.setSname("Vinod Kumar");
            stu.setSroll(101);
            stu.setScourse("MCA");
            em.persist(stu);
            entr.commit();
            System.out.println("Successfully added into database.");
        }
        catch(Exception e){
            System.out.println(e.getMessage());
        }
        finally{
            em.close();
        }
    }

}
