Jump to content

JavaEE how to insert new record on database


HarrySeah
 Share

Recommended Posts

hi , im try to do the java web to connect with managed bean and connect to the javaDB (entity) class

 

i trying to insert the record in the database but ....fail....

 

public void createUser(){

 

Booking book = new Booking();
book.setLessonno(this.l_id);
book.setCustomername(strName);
book.setCustomerphone(strPhone);
try {
utx.begin();
em.persist(book);
utx.commit();
} catch (Exception e) {
throw new RuntimeException(e);
}

 

}

 

this come out a error ....

java.lang.UnsupportedOperationException: Not supported yet.

 

 

public void updateDB(){

EntityManagerFactory emfactory = Persistence.createEntityManagerFactory("testTrainingPU");
EntityManager entitymanager = emfactory.createEntityManager();
entitymanager.getTransaction().begin();
Lesson lesson = entitymanager.find(Lesson.class, this.l_id);
lesson.setQuantity(lesson.getQuantity()-1);
entitymanager.getTransaction().commit();
Booking book = new Booking();
book.setCustomername(strName);
book.setCustomerphone(strPhone);
book.setLessonno(this.l_id);
entitymanager.persist(book);
entitymanager.getTransaction().commit();
entitymanager.close();
emfactory.close();
}
this way also same
so how i need to solve it ...thanks
Edited by HarrySeah
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...