i am trying to test ibatis with DB. I get NullPointerException. Below are the class and ibatis bean config,
<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);
}
}
I want to select and insert. I have marked as ** ** as a point of exception in above code
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)