为了账号安全,请及时绑定邮箱和手机立即绑定

在mysql(JAVA hibernate)中调用存储过程时出错

在mysql(JAVA hibernate)中调用存储过程时出错

ITMISS 2021-09-29 16:28:38
我有一个奇怪的问题,我可以MySQL成功调用存储过程。但是使用 using 调用它会Java返回错误。以下是我的控制器方法:public double getBalance(String number) {    double balance ;    try {        Query query = getSession().createSQLQuery("CALL getBalance(:string_number)").addEntity(Wallet.class)                .setParameter("string_number", number);        List result = query.list();        if (result.size() == 0) {            balance = -1.0;        } else {            balance = (double) result.get(0);        }    } catch (Exception ex) {        throw ex;    }    return balance;}这是我的存储过程:CREATE DEFINER=`root`@`localhost` PROCEDURE `getBalance`(IN string_number varchar(19))BEGINselect amount from wallet where number=string_number;END错误是:SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/DigitalWallet] threw exception [Request processing failed; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query] with root causejava.sql.SQLException: Column 'number' not found.我有数字列,我可以成功调用 MySQL Workbench 中的存储过程。
查看完整描述

1 回答

?
汪汪一只猫

TA贡献1898条经验 获得超8个赞

您应该改用该doWork()函数,您基本上可以使用 Lambda 表达式创建连接。你可以在这里看到一些例子


查看完整回答
反对 回复 2021-09-29
  • 1 回答
  • 0 关注
  • 239 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号