这样写没问题:
JdbcTemplate jt = new JdbcTemplate(dataSource);
String sql = "select count(1) from t_sale_type where sale_type='"+saleType+"'";
return jt.queryForInt(sql);
这样写有问题:
JdbcTemplate jt = new JdbcTemplate(dataSource);
String sql = "select count(1) from t_sale_type where sale_type=?";
return jt.queryForInt(sql, new Object[]{saleType});
报错信息:
java.lang.NullPointerException
at weblogic.utils.wrapper.WrapperFactory.getCachedWrapperClass(WrapperFactory.java:52)
at weblogic.utils.wrapper.WrapperFactory.getWrapperClass(WrapperFactory.java:242)
at weblogic.utils.wrapper.WrapperFactory.getWrapperClass(WrapperFactory.java:230)
at weblogic.utils.wrapper.WrapperFactory.createWrapper(WrapperFactory.java:219)
at weblogic.jdbc.wrapper.JDBCWrapperFactory.getWrapper(JDBCWrapperFactory.java:184)
at weblogic.jdbc.rmi.internal.PreparedStatementStub.readResolve(PreparedStatementStub.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadResolve(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at weblogic.utils.io.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:195)
at weblogic.rjvm.MsgAbbrevInputStream.readObject(MsgAbbrevInputStream.java:565)
at weblogic.utils.io.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:191)
at weblogic.rmi.internal.ObjectIO.readObject(ObjectIO.java:62)
at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:217)
at weblogic.rmi.internal.BasicRemoteRef.invoke(BasicRemoteRef.java:224)
at weblogic.jdbc.rmi.internal.ConnectionImpl_weblogic_jdbc_wrapper_PoolConnection_oracle_jdbc_driver_T4CConnection_1030_WLStub.prepareStatement(Unknown Source)
at weblogic.jdbc.rmi.SerialConnection.prepareStatement(SerialConnection.java:212)
at org.springframework.jdbc.core.JdbcTemplate$SimplePreparedStatementCreator.createPreparedStatement(JdbcTemplate.java:1203)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:532)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:588)
------解决方案--------------------
谢谢分享。我把原文考过来了,以备遇到同样问题搜索到这个帖子的朋友参考:
------------------------------------------分割线------------------------------------------------
今天发现:spring jdbctemplate只要绑定参数情况下执行sql语句就报错
weblogic.jdbc.rmi.internal.ConnectionImpl_weblogic_jdbc_wrapper_PoolConnection
_oracle_jdbc_driver_T4CConnection_1030_WLStub.
prepareStatement(Unknown Source)
这样写没问题:
JdbcTemplate jt = new JdbcTemplate(dataSource);
String sql = “select count(1) from t_sale_type where sale_type=’”+saleType+”‘”;
return jt.queryForInt(sql);
这样写有问题:
JdbcTemplate jt = new JdbcTemplate(dataSource);
String sql = “select count(1) from t_sale_type where sale_type=?”;
return jt.queryForInt(sql, new Object[]{saleType});
报错信息:
java.lang.NullPointerException
at weblogic.utils.wrapper.WrapperFactory.getCachedWrapperClass(WrapperFactory.java:52)
at weblogic.utils.wrapper.WrapperFactory.getWrapperClass(WrapperFactory.java:242)
at weblogic.utils.wrapper.WrapperFactory.getWrapperClass(WrapperFactory.java:230)
at weblogic.utils.wrapper.WrapperFactory.createWrapper(WrapperFactory.java:219)
at weblogic.jdbc.wrapper.JDBCWrapperFactory.getWrapper(JDBCWrapperFactory.java:184)
at weblogic.jdbc.rmi.internal.PreparedStatementStub.readResolve(PreparedStatementStub.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadResolve(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at weblogic.utils.io.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:195)
at weblogic.rjvm.MsgAbbrevInputStream.readObject(MsgAbbrevInputStream.java:565)
at weblogic.utils.io.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:191)
at weblogic.rmi.internal.ObjectIO.readObject(ObjectIO.java:62)