Procedure for Execution.
1.
Select – New Project – Java EE
– Enterprise Application ‐> give project
name as Prog13‐> Then
select Only EJB & Web application module ‐> Click Finish.
2.
Select Services option in NetBeans ‐>
Databases ‐> Java DB‐> Right click and start the server ‐>
Right Click on sample‐> click connect
3. Look into jdbc://localhost:1527/Sample ‐> Click App‐> Right Click on Table‐>Create New table and
add columns to table.
4. Switch to project window ‐> Right Click prog13‐ejb ‐> New‐> Select Entity Classes from Database ‐>
Select Data Source as jdbc/sample ‐> Select Empinfo ‐> add ‐> next
5. Give package name as mypack ‐> next ‐> Finish. It creates mapping between table and Entity bean
and create Student.java class.
6. Right Click on prog13‐ejb ‐> New ‐> Select ‐> Session Bean for entity classes.... Select available
entity classes ‐>
Select mypacks.Empinfo ‐> Add ‐> Next ‐> Select local interface ‐> Finish. It will
creates AbstractFacade .java [Abstract class], StudentFacade.java [java class], StudentFacadeLocal.java
interface.
7. In EmpinfoFacade.java ‐> Add the following code
@Override
public void persist(Object obj)
{
em.persist(obj);
}
public void addsEmp(String eid,String ename)
{
Empinfo obj=new Empinfo();
obj.setEid(eid);
obj.setEname(ename);
persist(obj);
}
8. Right click on program13‐war ‐> new ‐> Servlet ‐> give the name as studEntity‐>give package name
mypack‐>next ‐> select deployment descriptor ‐> finish.
9. The right click on code window ‐> Select insert code ‐> call enterprise bean ‐> Select studentFacade
‐> ok. Observe the code appears inside the servlet as StudentFacadeLocal studentFacade.
10. Add the following code
try {
empinfoFacade.addsEmp("e100", "Bingo");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet NewServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Record inserted successfully" + "</h1>");
out.println("</body>");
out.println("</html>");
}
save it and leave the default additional doPost and doGet methods in the same page as it is.
11. Right click on the war file ‐> properties ‐> Select run ‐> give Relative URL as the /ServletName ‐>
ok.
12. Right click on the war file of servlet file and click run.
thank you mobiapps...
ReplyDeleteit helpme in my xam.......
Thank you.....
Deletealways........ stay tuned......
nice..
ReplyDeleteit is tell me more about ejb .
and how to create entity bean
nice.. step by step . probleme solved....
ReplyDeletethank you mobiapps
nice steps
ReplyDeletethnx for steps
ReplyDeletereally help me.....
ReplyDeletethanx.......
thank you.
ReplyDelete