0

I am trying to insert a record to the database using spring API SimpleJdbcInsert... But, its creating issue when model object carrying Boolean variable...If I set the Boolean variable as true, its actually inserting NULL value to the database... My code is like below...please please help me.. Thanks a lot in advance..

    DiscountController.java

            discount = getDiscountData();
            discount = discountService.saveDiscount(discount);

    public Discount getDiscountData() 
        {
            Discount discount = new Discount();
            discount.setDiscountSchemeName("Early Bird Incentive");
            discount.setSchemeType("Volume Discount");
            discount.setDiscountStartDate(DateUtil.stringToDate("01/01/2018"));
            discount.setDiscountEndDate(DateUtil.stringToDate("30/06/2018"));
            discount.setEnabled(true);
            return discount;
        }


    DiscountService.java

    @Override
        public Discount saveDiscount(Discount discount) throws Exception 
        {
            return discountDAO.saveDiscount(discount);
        }


    DiscountDAO.java




    @Override
        public Discount saveDiscount(Discount discount) throws ServiceException {

              String logStr = discount.toString();
              int ID = -1;

                  logger.debug(" Discount Insert: " + logStr);
                  SqlParameterSource discountParams = new BeanPropertySqlParameterSource(discount);
                  ID = new SimpleJdbcInsert(dataSource).withTableName("TBL_DISCOUNT")
                      .usingGeneratedKeyColumns("Id").executeAndReturnKey(discountParams).intValue();

                  if (ID <= 0)
                  {
                      logger.error(" Discount Insert: ID returned " + ID + ": " + logStr);
                      throw new Exception("Internal error while saving Discount information");
                  }
                  else
                  {
                      logger.info(" Discount Insert: ID returned " + ID + ": " + logStr);
                      discount.setID(ID);
                  }
    }// End of function

Discount.java


    public class Discount extends GenericEntity{

        private String discountSchemeName,schemeType;
        private Date discountStartDate,discountEndDate;
        private boolean isEnabled;

        public String getDiscountSchemeName() {
            return discountSchemeName;
        }

        public void setDiscountSchemeName(String discountSchemeName) {
            this.discountSchemeName = discountSchemeName;
        }

        public String getSchemeType() {
            return schemeType;
        }

        public void setSchemeType(String schemeType) {
            this.schemeType = schemeType;
        }

        public Date getDiscountStartDate() {
            return discountStartDate;
        }

        public void setDiscountStartDate(Date discountStartDate) {
            this.discountStartDate = discountStartDate;
        }

        public Date getDiscountEndDate() {
            return discountEndDate;
        }

        public void setDiscountEndDate(Date discountEndDate) {
            this.discountEndDate = discountEndDate;
        }

        public boolean getEnabled() {
            return isEnabled;
        }

        public void setEnabled(boolean isEndabled) {
            this.isEnabled = isEndabled;
        }
    }
rahul shalgar
  • 1,198
  • 5
  • 24
  • 39
  • I think the simple classes are deprecated now. You'd be better of using JdbcTemplate and avoiding their attempts at a more simple solution. – duffymo May 07 '18 at 14:08
  • @duffymo... The issue was.. wrong naming naming convention in setter & getter methods for boolean field isEnable... it should be setIsEnable(true) not setEnabled(true).. Thanks for the response... – rahul shalgar May 16 '18 at 04:19

0 Answers0