Jump to content

JavaEE how to insert new record on database


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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...