Products Downloads


French version


 

 

In this page, we are going to perform a series of actions enabling the implementation of standard database record management processes (i.e. Create, Modify and Delete).

 

The following code is not optimized, but clearly shows each step in the various processes. Once the various mechanisms have been mastered, you should seek to factorize certain sections of code.

 

You should also implement messages to notify the user of the operation's success or failure: these messages can simply be written in HTML.

 

1.   Create a blank new JSP page.

This page must have the ".jsp" extension. In our example, this page is called "indivprocess.jsp".

 

 

 

2.   Next, declare the Javabeans that are going to be used in the page, i.e. the Connection pool manager and the Process JavaBean created in the previous step.

 

 

<HTML>

<TITLE>Operations on a Customer</TITLE>

<BODY BGCOLOR="#FFFFFF">

<jsp:useBean class="com.hardis.adelia.pool.PoManager" id="Manager" scope="application"></jsp:useBean>

<jsp:useBean class="com.hardis.training.FDETCL" id="fDETCL"></jsp:useBean> 

 

 

 

3.   Retrieve the parameters entered by the user. These parameters will be manipulated in the form of "StringBuffers" for the sake of compatibility with the Adelia Bean lists.

Also retrieve the parameters that will determine the action required. The possible actions are: Create, Modify and Delete.

 

 

<%

String sAction=request.getParameter("CODACTION");

String sCode=request.getParameter("CODECLI");

StringBuffer sCodeCust=new StringBuffer(request.getParameter("chsCodeCust"));

StringBuffer sName=new StringBuffer(request.getParameter("chsName"));

StringBuffer sAddress=new StringBuffer(request.getParameter("chsAddress"));

StringBuffer sZip=new StringBuffer(request.getParameter("chsZip"));

StringBuffer sCity=new StringBuffer(request.getParameter("chsCity"));

StringBuffer sCusAcc=new StringBuffer(request.getParameter("chsCusAcc"));

StringBuffer sCusBank=new StringBuffer(request.getParameter("chsCusBank"));

String sCreate=request.getParameter("btnCreate");

String sModify=request.getParameter("btnModify");

String sDelete=request.getParameter("btnDelete");  

 

 

4.   With record creation processes, begin by correctly specifying the list that populates the JavaBean with the elements to be created in the database.

Then, after specifying the action code, transfer the data to the data server.
The Bean's return code MUST be tested, in order to establish whether the operation was completed successfully.

// Creating a record

if (sCreate!= null){

try

{

        StringBuffer sbBuf = new StringBuffer(" ");

        fDETCL.setPCOD_CUS(sCodeCust.toString());

 

         fDETCL.setLST_CUST(sCodeCust,

sName,

sAddress,

sbBuf,

sCity,

sbBuf,

sZip,

Integer.parseInt(sCusBank.toString()),

sCusAcc,

sbBuf,

sbBuf);

         fDETCL.setCODACTION("CREATE");

         Manager.refresh(fDETCL);

}

catch (Exception e)

{

         // Error message

}

if (fDETCL.isOK())

{

         // If action was performed successfully

}

else

{

         // If action failed

}

 

 

5.   The procedure for a modification is exactly the same: clearly, users with the appropriate instruction handling know-how should consider factorizing the code.

// Modifying a record

if (sModify != null){

          StringBuffer sbBuf = new StringBuffer(" ");

        fDETCL.setPCOD_CUS(sCodeCust.toString());

 

         fDETCL.setLST_CUST(sCodeCust,

sName,

sAddress,

sbBuf,

sCity,

sbBuf,

sZip,

Integer.parseInt(sCusBank.toString()),

sCusAcc,

sbBuf,

sbBuf);

        fDETCL.setCODACTION("MODIFY");

        Manager.refresh(fDETCL);

}

catch (Exception e)

{

         // Error message

}

if (fDETCL.isOK())

{

         // If action was performed successfully

}

else

{

         // If action failed

}

 

 

6.   A record deletion is easier to implement, as you can simply set the relevant action code and ID code.

// Deleting a record

if (sDelete!= null){

try

{

         fDETCL.setCODACTION("DELETE");

         fDETCL.setPCOD_CUS(sCodeCust.toString());

         Manager.refresh(fD ETCL);

}

catch (Exception e)

{

         // Error message

}

if (fDETCL.isOK())

{

         // If action was performed successfully

}

else

{

         // If action failed

}

 

 

↑ Top of page

  • Aucune étiquette