ibatis抛出NullPointerException

时间:2012-11-05 06:54:21

标签: ibatis

我正在尝试用DB测试iBATIS。我得到一个NullPointerException。下面是类和iBATIS bean配置,

  <select id="getByWorkplaceId"
  parameterClass="java.lang.Integer" resultMap="result">
  select * from WorkDetails where workplaceCode=#workplaceCode#
  </select>

  <select id="getWorkplace" resultClass="com.ibatis.text.WorkDetails">
  select * from WorkDetails
  </select>

POJO

public class WorkplaceDetail implements Serializable {
private static final long serialVersionUID = -6760386803958725272L;
private int code;
private String plant;
private String compRegNum;
private String numOfEmps;
private String typeIndst;
private String typeProd;    
private String note1;
private String note2;
private String note3;
private String note4;
private String note5;       
}

DAOimplementation

public class WorkplaceDetailImpl implements WorkplaceDetailsDAO {

private SqlMapClient sqlMapClient;

public void setSqlMapClient(SqlMapClient sqlMapClient) {
    this.sqlMapClient = sqlMapClient; 
    }

@Override
public WorkplaceDetail getWorkplaceDetail(int code) {
    WorkplaceDetail workplaceDetail=new WorkplaceDetail();
    try{
            **workplaceDetail= (WorkplaceDetail) this.sqlMapClient.queryForObject("workplaceDetail.getByWorkplaceId", code);**


    }catch (SQLException sqlex){
        sqlex.printStackTrace();
    }
    return workplaceDetail;
}

TestCode

public class TestDAO {

public static void main(String args[]) throws Exception{
    WorkplaceDetail wd = new WorkplaceDetail(126, "Hoonkee", "1234", "22", "Service", "Tele", "hsgd","hsgd","hsgd","hsgd","hsgd");

    WorkplaceDetailImpl impl= new WorkplaceDetailImpl();
    **impl.getWorkplaceDetail(wd.getCode());**
    impl.saveOrUpdateWorkplaceDetails(wd);
    System.out.println("dhsd"+impl);


}
}

我想选择并插入。我在上面的代码

中标记为** **作为例外点
Exception in thread "main" java.lang.NullPointerException
at com.ibatis.text.WorkplaceDetailImpl.getWorkplaceDetail(WorkplaceDetailImpl.java:19)
at com.ibatis.text.TestDAO.main(TestDAO.java:11)

0 个答案:

没有答案