谢谢,我调试没有错误。还有ID应该也不存在问题我用的是JAVA的UUID生成的。
我调试、测试都没有问题的。所以不知道问题所在?

解决方案 »

  1.   

    好的。
    action:
    /*
     * This project is ghx
     * Created on 2007-1-10 下午02:30:37                                          
     * File is Applay4counterbillAddAction.java
     */package com.gionee.action.applay4counterbill;
    import java.util.List;import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;import com.gionee.action.BaseActionSupport;
    import com.gionee.common.Constants;
    import com.gionee.common.util.GeneralUtil;
    import com.gionee.common.util.LoggerUtil;
    import com.gionee.ghx.facade.BusinessAgentFacade;
    import com.gionee.ghx.facade.CityFacade;
    import com.gionee.ghx.facade.applay.Applay4counterbillFacade;
    import com.gionee.ghx.help.BusinessAgentHelper;
    import com.gionee.ghx.help.CityHelper;
    import com.gionee.ghx.vo.Applay4counterbill;
    import com.gionee.ghx.vo.AuthUser;
    import com.gionee.ghx.vo.BusinessAgent;
    import com.gionee.ghx.vo.UserSession;
    import com.opensymphony.xwork.ActionContext;
    /**
     * @author 
     */public class Applay4counterbillAddAction extends BaseActionSupport { /**
     * 
     */
    private static final long serialVersionUID = -5493210177483110447L; private static final Log log=LogFactory.getLog(Applay4counterbillAddAction.class);

    private Applay4counterbill applay4counterbill;

    private List applay4counterbilldetails;

    private List citys;

    private List stores;

    /**
     * 
     */
    public String execute() throws Exception{
    AuthUser authUser = ((UserSession)ActionContext.getContext().getSession().get(Constants.USER_SESSION)).getAuthUser();
    //查询所属总代
    BusinessAgent businessAgent=new BusinessAgentFacade().findById(" select agentId,provinceId,provinceName "+new BusinessAgentHelper().getSqlString()+" and agentId='"+authUser.getAgentId()+"'","agentId,provinceId,provinceName");
    //城市区域
    citys=new CityFacade().find("select "+CityHelper.City_Fields+new CityHelper().getSqlString()+" and agentId='"+businessAgent.getAgentId()+"'",CityHelper.City_Fields);
         return "add";
    }

    /***
     * 展柜制作申请保存
     * @return
     * @throws Exception
     */
    public String doSave() throws Exception {
    //key
    String uuid=GeneralUtil.UUID();
    try{
    Applay4counterbillFacade facade=new Applay4counterbillFacade();
    AuthUser authUser = ((UserSession)ActionContext.getContext().getSession().get(Constants.USER_SESSION)).getAuthUser();
    applay4counterbill.setApplaybillId(uuid);
    log.info("applaybillId: "+applay4counterbill.getApplaybillId());
    applay4counterbill.setCreateDate(new java.util.Date());
    applay4counterbill.setCreatePerson(authUser.getUserId());
    applay4counterbill.setCreatePersonName(authUser.getUserName());
    applay4counterbill.setAgentId(authUser.getAgentId());
    applay4counterbill.setAgentName(authUser.getAgentName());
    applay4counterbill.setAgentSort(authUser.getAgentSort());
    facade.save(applay4counterbill);
    this.setMessage("新增展柜制作申请成功!");
    this.setContinueUri("Applay4counterbillFormView.htm?applaybillId="+applay4counterbill.getApplaybillId());
    }
    catch(Exception e){
    this.setMessage("新增展柜制作申请失败!");
    this.setReturnUri("Applay4counterbillFormList.htm");
    LoggerUtil.error(this.getClass(), getMessage(), e);
    return ERROR;
    }
    return SUCCESS;
    }
    get和set属性
    Facade层(service)就是调用DAO层的insert
    public void save(Applay4counterbill applay4counterbill) throws Exception
    {
    DbConnection dbconn = new DbConnection();
    try
    {
    dbconn.begin();
      applay4counterbillDAO.insert(applay4counterbill, dbconn);
    dbconn.commit();
    }
    catch(Exception e)
    {
    e.printStackTrace();
    log.error("新增失败!");
    dbconn.rollback();
    throw e;
    }
    finally
    {
    if(dbconn!=null)dbconn.closed();
    }
    }
    DAO层:
    public void insert(Applay4counterbill applay4counterbill,DbConnection dbconn) throws java.sql.SQLException {
    try {
    String fields = helper.getFields(applay4counterbill);
    String sql = helper.createInsertSql(fields);
    dbconn.buildPreparedStatement(sql);
    helper.pstmtInsert(applay4counterbill, dbconn.getCurrentPstmt(), fields);
    dbconn.getCurrentPstmt().execute();
    }
    catch(Exception e) {
    e.printStackTrace();
    log.error("新增失败!");
    throw new java.sql.SQLException();
    }
    }
    还有help类是我包数据库表SQL装换