| |
|
Add Record : 1 html and 1 JSP File Required
|
|
addcustomer.html save it in E:/Phone/html/ directory
|
|
Modify Record : 1 html and 2 JSP Files Required
|
|
modcustomer.html save it in E:/Phone/html/ directory
|
|
Delete Record : 1 html and 1 JSP Files Required
|
delcustomer.html save it in E:/Phone/html/ directory
James Smith's Java : james_smith73@yahoo.com
Connect to JNDI lookup
use home.remove() passing the Primary key , so that record can be deleted from the database
// Connect to JNDI lookup --------------------------------------------------------------------
Context initial = new InitialContext();
Object objRef = initial.lookup("ManageCustBeanJNDI");
ManageCustHome home = (ManageCustHome) PortableRemoteObject.narrow(objRef, ManageCustHome.class);
ManageCustRemote MR = null;
// Verify Details Below : --------------------------------------------------------------------------
MR = home.findByPrimaryKey(CustId);
CustName = MR.getCustName();
CustPh = MR.getCustPh();
CustPlan = MR.getCustPlan();
home.remove(CustId);
delcustresp.jsp save it in E:/Phone/jsp/ directory
James Smith's Java : james_smith73@yahoo.com
|
|
View Single Record
|
viewcustomer.html save it in E:/Phone/html/ directory
James Smith's Java : james_smith73@yahoo.com
A single record is found by using its primary key , the below code will run a select query to identify the record related to it
in the database
// Connect to JNDI lookup --------------------------------------------------------------------
Context initial = new InitialContext();
Object objRef = initial.lookup("ManageCustBeanJNDI");
ManageCustHome home = (ManageCustHome) PortableRemoteObject.narrow(objRef, ManageCustHome.class);
ManageCustRemote MR = null;
// Verify Details Below : --------------------------------------------------------------------------
MR = home.findByPrimaryKey(CustId);
CustId = MR.getCustId();
CustName = MR.getCustName();
CustPh = MR.getCustPh();
CustPlan = MR.getCustPlan();
viewcust.jsp be stored in the E:/Phone/jsp/ directory
James Smith's Java : james_smith73@yahoo.com
|
|
View Multiple Records
|
viewrange.html save it in E:/Phone/html/ directory
James Smith's Java : james_smith73@yahoo.com
since we are seaching a range of recods we need to give upper and lower limit of customer Id value
we get records back from EJB as a Collection or Array , we need to decode them into single records
Save viewrangeresp.jsp in E:/Phone/jsp directory
// Connect to JNDI lookup --------------------------------------------------------------------
Context initial = new InitialContext();
Object objRef = initial.lookup("ManageCustBeanJNDI");
ManageCustHome home = (ManageCustHome) PortableRemoteObject.narrow(objRef, ManageCustHome.class);
ManageCustRemote MR = null;
// Call Create Method --------------------------------------------------------------------
int ilowerlim = Integer.parseInt(lowerlim);
int iupperlim = Integer.parseInt(upperlim);
Collection CRArray = home.findInRange(ilowerlim,iupperlim);
Iterator it = CRArray.iterator();
...............
while (it.hasNext())
{
Object objRef2 = it.next();
MR = (ManageCustRemote)PortableRemoteObject.narrow(objRef2, ManageCustRemote.class);
CustId = MR.getCustId();
CustName = MR.getCustName();
CustPh = MR.getCustPh();
CustPlan = MR.getCustPlan();
cntr++;
// Display Records in a table here --------
}
..............
Complete Code Below
James Smith's Java : james_smith73@yahoo.com
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="javax.naming.*" %>
<%@ page import="javax.rmi.PortableRemoteObject" %>
<%@ page import="EJB.ManageCust.*" %>
<%
String lowerlim=request.getParameter("lowerlim");
String upperlim = request.getParameter("upperlim");
String CustId = null;
String CustName = null;
String CustPh = null;
String CustPlan = null;
int NoOfCalls = 0;
boolean success = false;
int cntr = 0;
try
{
// Connect to JNDI lookup --------------------------------------------------------------------
Context initial = new InitialContext();
Object objRef = initial.lookup("ManageCustBeanJNDI");
ManageCustHome home = (ManageCustHome) PortableRemoteObject.narrow(objRef, ManageCustHome.class);
ManageCustRemote MR = null;
// Call Create Method --------------------------------------------------------------------
int ilowerlim = Integer.parseInt(lowerlim);
int iupperlim = Integer.parseInt(upperlim);
Collection CRArray = home.findInRange(ilowerlim,iupperlim);
Iterator it = CRArray.iterator();
%>
| Customer ID |
Customer Name |
Phone |
Plan |
<%
while (it.hasNext())
{
Object objRef2 = it.next();
MR = (ManageCustRemote)PortableRemoteObject.narrow(objRef2, ManageCustRemote.class);
CustId = MR.getCustId();
CustName = MR.getCustName();
CustPh = MR.getCustPh();
CustPlan = MR.getCustPlan();
cntr++;
%>
| <%=CustId%> |
<%=CustName%> |
<%=CustPh%> |
<%=CustPlan%> |
<%
}
%>
<%
success = true;
}
catch (Exception ex)
{
System.out.println("Invalid Range , so no Records to View ");
System.err.println("Caught an exception.");
ex.printStackTrace();
}
%>
<%
if (success && cntr > 0)
{
%>
|
Message Box !
|
|
|
<%=cntr%> Customer(s) Found Successfully
|
<%
}
else
{
%>
|
Message Box !
|
|
|
Could not find Customers please check to and from range to be a valid number
From number must be less than To number of Customer ID
|
<%
}
%>
|
|
What Next => Available : NO
|
|
Chapter 7. Deploying EJBs and Web Components
|
|
Reach me!
|
|
|
Java, J2EE, J2SE and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc.
in the United States and other countries.
|
|