java.lang.NullPointerException.
MyDAO$2.setValues
org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:680)
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:454)
org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:676)
org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:738)
net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:694)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:639)
我的代碼是
this.jdbcTemplate.update(SOME_SQL_UPDATE, new PreparedStatementSetter() {
public void setValues(PreparedStatement ps) throws SQLException {
ps.setBoolean(1, myObj.isVal1());
ps.setString(2, myObj.getVal2().toString());
}
});
public class myObj {
private boolean val1;
private Enum val2;
}
我的布爾分貝列數是(1,0)和我的組字符串列是VARCHAR 。
注:我使用Spring 1.2的,現在升級到彈簧3
出了什麼問題?
我該如何解決這個問題?
myObj不爲null –
myObj.val2也可以爲null,在調用toString()時可能會拋出NPE。 – matts