有没熟悉Mybatis的高手帮我看看为什么不能添加信息
做一个添加异常信息的功能,但在dao实现类中一直报空引用异常,不能插入数据在表中:
这是mapper.xml里面的语句
<!-- 添加异常日志 -->
<insert id="addException" parameterType="el">
<selectKey resultType="String" keyProperty="iden" order="BEFORE">
select FRM_EXECPTION_IDEN.nextVal from dual
</selectKey>
Insert Into FRM_EXCEPTION(iden,yhdh,ip,classname,methodname,execptoninfo,execptiontime,bz) Values (#{iden},#{yhdh},#{ip},#{className},#{methodName},#{exceptionInfo},#{exceptionTime},#{bz})
</insert>
dao实现类:
public int addException(ExceptionLog el) {
return sqlSessionTemplate.insert(ADDEXCEPTION, el);//就是这个报空引用异常
}
测试类:
public static void main(String[] args) {
// TODO Auto-generated method stub
SyslogDao logDao=new SyslogDaoImpl();
ExceptionLog el=new ExceptionLog();
try{
Syslog log=null;
log.setCity("");
}catch(Exception e){
System.out.println(e.toString());
el.setYhdh("21312");
el.setIp("000.000.");
el.setClassName(e.getStackTrace()[0].getClassName());//保存类名
el.setMethodName(e.getStackTrace()[0].getMethodName());//保存方法名
el.setExceptionInfo(Tools.getException(e));
el.setExceptionTime(new Date());
el.setBz("--");
System.out.println(el.getClassName());
int i=logDao.addException(el);
}
}
运行报错,数据插入失败:
java.lang.NullPointerExceptiontest.Etest
Exception in thread "main" java.lang.
NullPointerException at com.zlkj.frmwork.dao.impl.SyslogDaoImpl.addException(SyslogDaoImpl.java:42)
at test.Etest.main(Etest.java:35)
------解决方案--------------------