ibatis 调用存储过程报java.lang.NullPointerException错,50分相谢!!

capricornwq 2007-06-25 11:06:48
(1)我的xml:
<parameterMap id="invoiceInsertMap" class="java.util.map" >
<parameter property="invoicestart" jdbcType="NUMBER" javaType="java.lang.Long" mode="IN"/>
<parameter property="totalnum" jdbcType="NUMBER" javaType="java.lang.Integer" mode="IN"/>
<parameter property="invoicebookid" jdbcType="NUMBER" javaType="java.lang.Integer" mode="IN"/>
</parameterMap>
<procedure id="invoiceInsert" parameterMap="invoiceInsertMap" >
{call invoiceInsert (?,?,?)}
</procedure>
(2)invoiceInsert 为数据库中存储过程,代码无误

(3)对外调用的接口:
public int invoiceInsert(InvoiceBook invoicebook) {
HashMap paramMap = new HashMap();
paramMap.put("invoicestart", invoicebook.getInvoicestart());
paramMap.put("totalnum", invoicebook.getInvoicedicid());
paramMap.put("invoicebookid", invoicebook.getInvoicebookid());
return invoiceDao.invoiceInsert(paramMap);

}
(4)invoiceDao 对xml配置中调用:
public int invoiceInsert(HashMap paramMap) {
int i=0;
try{
daoManager.startTransaction();
i=((Integer)queryForObject("invoiceInsert",paramMap)).intValue();
daoManager.commitTransaction();
}catch(Exception e ){
e.printStackTrace();
}
return i;
}

控制台打印的结果
{call invoiceInsert (?,?,?)}
[100000000, 20, 1]
Types: [java.lang.Long, java.lang.Integer, java.lang.Integer]
java.lang.NullPointerException
如果可以给个实例,也万分感谢!!!
...全文
657 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
superlanneret 2007-07-05
  • 打赏
  • 举报
回复
{call invoiceInsert (#invoicestart#,#totalnum#,#invoicebookid#)}
这样试一下看看可以吗?
capricornwq 2007-07-05
  • 打赏
  • 举报
回复
i=((Integer)queryForObject("invoiceInsert",paramMap)).intValue();
有(Integer) 和intValue(),已经进行类型转换了
存储过程中 我也修改成有返回值的,问题在,存储过程没有调用

superlanneret 2007-07-05
  • 打赏
  • 举报
回复
Product product = (Product)sqlMap.queryForObject
(“getProduct”, key);你看看这句话就会明白了。
superlanneret 2007-07-05
  • 打赏
  • 举报
回复
queryForObject 返回的是一个对象,你用的是一个整形变量。
suncheng_hong 2007-07-05
  • 打赏
  • 举报
回复
看日志
superlanneret 2007-07-04
  • 打赏
  • 举报
回复
建议你Debug一下看看里面参数的值有没有
capricornwq 2007-07-04
  • 打赏
  • 举报
回复
Debug paramMap 中有值,
的确是i=((Integer)queryForObject("invoiceInsert",paramMap)).intValue();出错
此句调用
<procedure id="invoiceInsert" parameterMap="invoiceInsertMap" >
{call invoiceInsert (10000000, 20, 1)} //此处已将参数赋值,与参数传递无关
</procedure>
然后报错为:
Failed to execute queryForObject - id [invoiceInsert], parameterObject [{invoicebookid=6, totalnum=20, invoicestart=12}]. Cause: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in dlk/invoice/invoice.xml.
--- The error occurred while applying a parameter map.
--- Check the Invoice.invoiceInsertMap.
--- Check the parameter mapping for the 'invoicestart' property.
--- Cause: java.sql.SQLException: Invalid parameter index 1.
冒似invoicestart传参出错,在存储过程中@invoicestart bigint,改成 int也一样的错
有人可以再指教一下么?
如何判断 此句{call invoiceInsert (10000000, 20, 1)}是否调用了 名字为invoiceInsert 的存储过程, 是不是存储过程名需要定义什么的?
再次请教各位高手。。。
cseu 2007-07-03
  • 打赏
  • 举报
回复
NullPointerException是最常见的一种错误了。
我对ibatis、存储过程都不是太了解,对你的程序也了解。
不过我推测是这一句报的nullpointer:i=((Integer)queryForObject("invoiceInsert",paramMap)).intValue();
queryForObject返回了null,你debug一下看看
iwillrockyou 2007-07-03
  • 打赏
  • 举报
回复
帮定~
capricornwq 2007-07-03
  • 打赏
  • 举报
回复
如果把 xml中的写成
<procedure id="invoiceInsert" parameterMap="invoiceInsertMap" >
{call invoiceInsert (10000000, 20, 1)}
</procedure>

报错为:
com.ibatis.dao.client.DaoException: Failed to execute queryForObject - id [invoiceInsert], parameterObject [{invoicebookid=1, totalnum=20, invoicestart=10000000}]. Cause: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in dlk/invoice/invoice.xml.
--- The error occurred while applying a parameter map.
--- Check the Invoice.invoiceInsertMap.
--- Check the parameter mapping for the 'invoicestart' property.
--- Cause: java.sql.SQLException: Invalid parameter index 1.
invoicestart 有什么问题么?
有人指教一二么?


capricornwq 2007-07-03
  • 打赏
  • 举报
回复
CREATE PROCEDURE dbo.invoiceInsert
@invoicestart bigint,
@totalnum int,
@invoicebookid int

AS
BEGIN TRAN


Declare @invoiceId as int
Declare @count as int

select @invoiceId= max(invoiceId) from invoice where tag=1
IF @invoiceId Is Not Null
set @invoiceId=@invoiceId+1
else
set @invoiceId=1

set @count=@totalnum
while @count>0
Begin
Insert Into invoice(invoiceId,tag,invoiceNumber,invoicebookid)
Values(@invoiceId,'1',@invoicestart,@invoicebookid)
set @invoiceId=@invoiceId+1
set @invoicestart=@invoicestart+1
set @count=@count-1
End


IF @@ERROR<>0 GOTO errhandle---->發生錯誤直接跳轉到後面,不發生錯誤提交
COMMIT TRAN
SELECT 1

errhandle:
IF @@ERROR<>0
BEGIN
ROLLBACK TRAN
SELECT 0
END
GO
存储过程如上
capricornwq 2007-07-03
  • 打赏
  • 举报
回复
{call invoiceInsert (?,?,?)}
[100000000, 20, 1] 不就是有传值么? debug了 也都有值,没有人知道么?
superlanneret 2007-06-25
  • 打赏
  • 举报
回复
paramMap.put("invoicestart", invoicebook.getInvoicestart());
paramMap.put("totalnum", invoicebook.getInvoicedicid());
paramMap.put("invoicebookid", invoicebook.getInvoicebookid());
你Debug一下看看这里面的参数是不是都有值啊?

81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧