You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Struts234 <st...@gmail.com> on 2009/09/01 00:32:36 UTC

code inserting data into database twice

Hi folks,


    I wrote the following code to insert values into database. But it's
crazy, this is inserting the values twice. here are the code below.

    if(activity.equalsIgnoreCase("
    declineParticipation")){
                   
                    if(isTokenValid(request)){

                        // Validate the supervisor Info..
                        TeleworkDelegate delegate = new TeleworkDelegate();
                        String[] supervisorInfo =
delegate.validateSupervisorEmail(theForm.getSupervisorEmail().toLowerCase());
                        String supervisorCustomerId = supervisorInfo[2];
                        String role = supervisorInfo[3];
                         // Update the supervisor info into database..
                        user.setSupervisorName(supervisorInfo[1]+ " " +
supervisorInfo[0]);
                       
user.setSupervisorEmail(theForm.getSupervisorEmail());
                       
delegate.updateSupervisorInfo(user,supervisorCustomerId );
                  
                        // Generate unique agreement number..
                        int teleworkAgreementId =
delegate.generateTeleworkAgreementNumber();
                        // call the create agreement method to insert data
into DB..
                       
createDeclineParticipation(user,teleworkAgreementId);
                        // update the decline participation info into DB
                        delegate.declineParticipation(user);                               
// 4
                        return mapping.findForward("logon");
                    }
                    else
                    {
                        request.setAttribute("errorKey", new
String("error.telework.teleworkagreement.duplicatesubmission"));
                        return mapping.findForward("logon");
                    }
                }
       

    private void createDeclineParticipation(UserInfoVO user, int
teleworkAgreementId ) throws DatabaseException, TeleworkException {
            // TODO Auto-generated method stub
            TeleworkDelegate teleworkDelegate = new TeleworkDelegate();
            TeleworkScheduleVO scheduleVO = new TeleworkScheduleVO();
            TeleworkAgreementVO agreementVO = new TeleworkAgreementVO();
            scheduleVO.setTeleworkAgreementID(teleworkAgreementId);
            agreementVO.setTeleworkAgreementId(teleworkAgreementId);
            agreementVO.setDateCompletedTraining("07/21/2009");
            agreementVO.setAgreementStatus(Constants.AGREEMENT_DECLINED);
            teleworkDelegate.createDeclineTeleworkAgreement(user,
scheduleVO, agreementVO);
        }


    this code is generating 2 unique number and inserting values twice into
database. Means, when i hit a submit button, it has to get the max number
from the database and add 1 to it and insert the record. instead of it, it
is inserting twice. Ex when i hit the submit botton, it has to get the
number is 4, but it's inserting 4 and 5 into the database.

    don't know why it's doing like, I would appreciate if you could help me
on this.

    Thanks,

-- 
View this message in context: http://www.nabble.com/code-inserting-data-into-database-twice-tp25231274p25231274.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: code inserting data into database twice

Posted by Tommy Pham <to...@yahoo.com>.
----- Original Message ----
> From: Struts234 <st...@gmail.com>
> To: user@struts.apache.org
> Sent: Monday, August 31, 2009 3:32:36 PM
> Subject: code inserting data into database twice
> 
> 
> Hi folks,
> 
> 
>     I wrote the following code to insert values into database. But it's
> crazy, this is inserting the values twice. here are the code below.
> 
>     if(activity.equalsIgnoreCase("
>     declineParticipation")){
>                   
>                     if(isTokenValid(request)){
> 
>                         // Validate the supervisor Info..
>                         TeleworkDelegate delegate = new TeleworkDelegate();
>                         String[] supervisorInfo =
> delegate.validateSupervisorEmail(theForm.getSupervisorEmail().toLowerCase());
>                         String supervisorCustomerId = supervisorInfo[2];
>                         String role = supervisorInfo[3];
>                          // Update the supervisor info into database..
>                         user.setSupervisorName(supervisorInfo[1]+ " " +
> supervisorInfo[0]);
>                       
> user.setSupervisorEmail(theForm.getSupervisorEmail());
>                       
> delegate.updateSupervisorInfo(user,supervisorCustomerId );
>                   
>                         // Generate unique agreement number..
>                         int teleworkAgreementId =
> delegate.generateTeleworkAgreementNumber();
>                         // call the create agreement method to insert data
> into DB..
>                       
> createDeclineParticipation(user,teleworkAgreementId);
>                         // update the decline participation info into DB
>                         delegate.declineParticipation(user);                    
>           
> // 4
>                         return mapping.findForward("logon");
>                     }
>                     else
>                     {
>                         request.setAttribute("errorKey", new
> String("error.telework.teleworkagreement.duplicatesubmission"));
>                         return mapping.findForward("logon");
>                     }
>                 }
>       
> 
>     private void createDeclineParticipation(UserInfoVO user, int
> teleworkAgreementId ) throws DatabaseException, TeleworkException {
>             // TODO Auto-generated method stub
>             TeleworkDelegate teleworkDelegate = new TeleworkDelegate();
>             TeleworkScheduleVO scheduleVO = new TeleworkScheduleVO();
>             TeleworkAgreementVO agreementVO = new TeleworkAgreementVO();
>             scheduleVO.setTeleworkAgreementID(teleworkAgreementId);
>             agreementVO.setTeleworkAgreementId(teleworkAgreementId);
>             agreementVO.setDateCompletedTraining("07/21/2009");
>             agreementVO.setAgreementStatus(Constants.AGREEMENT_DECLINED);
>             teleworkDelegate.createDeclineTeleworkAgreement(user,
> scheduleVO, agreementVO);
>         }
> 
> 
>     this code is generating 2 unique number and inserting values twice into
> database. Means, when i hit a submit button, it has to get the max number
> from the database and add 1 to it and insert the record. instead of it, it
> is inserting twice. Ex when i hit the submit botton, it has to get the
> number is 4, but it's inserting 4 and 5 into the database.
> 
>     don't know why it's doing like, I would appreciate if you could help me
> on this.
> 
>     Thanks,
> 
> -- 
> View this message in context: 
> http://www.nabble.com/code-inserting-data-into-database-twice-tp25231274p25231274.html
> Sent from the Struts - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org

Why not just insert the data into a table and get the generated key from identity (primary key) column?  If you're using surrogate key, better to implement stored procedure?  If the data insertion spans multiple tables, transactions + generated key return ??

Any case, you might want to take a closer look at your teleworkDelegate.createDeclineTeleworkAgreement()... this might your problem ;)

Regards,
Tommy


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org