Hibernate

Main java class

Step: 5

Previous Home Next

PersistTest.java

package r4r;
import java.util.*;
import org.hibernate.Session;
import org.hibernate.Transaction;
public class PersistTest {
public static void main(String[] args) {
Scanner in=new 
Scanner(System.in);
Session session=SessionProvider.getSession();
Transaction t=session.beginTransaction();
while(true)
{
System.out.println("Enter Name:"
);
String n=in.nextLine();
System.out.println("Enter Job:");
String j=in.nextLine();
System.out.println("Enter Salary:"
);
int s=in.nextInt(); in.nextLine();// to remove unread newline character.
Emp e=new Emp(n,j,s);
session.save(e);
System.out.println("want to persist more objects yes/no?"
);
String ans=in.nextLine();
if(ans.equals("no"))
break;
}
t.commit();
session.close();
System.out.println("successfully persisted."
);
}
}
Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: