(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
如果可以给个实例,也万分感谢!!!
<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
如果可以给个实例,也万分感谢!!!
paramMap.put("totalnum", invoicebook.getInvoicedicid());
paramMap.put("invoicebookid", invoicebook.getInvoicebookid());
你Debug一下看看这里面的参数是不是都有值啊?
[100000000, 20, 1] 不就是有传值么? debug了 也都有值,没有人知道么?
@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
存储过程如上
<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 有什么问题么?
有人指教一二么?
我对ibatis、存储过程都不是太了解,对你的程序也了解。
不过我推测是这一句报的nullpointer:i=((Integer)queryForObject("invoiceInsert",paramMap)).intValue();
queryForObject返回了null,你debug一下看看
的确是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 的存储过程, 是不是存储过程名需要定义什么的?
再次请教各位高手
(“getProduct”, key);你看看这句话就会明白了。
有(Integer) 和intValue(),已经进行类型转换了
存储过程中 我也修改成有返回值的,问题在,存储过程没有调用
这样试一下看看可以吗?