我有一个奇怪的问题,我可以成功调用MySQL
存储过程。但是使用Java
调用它会返回错误。
以下是我的Controller方法:
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))
BEGIN
select 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 cause
java.sql.SQLException: Column 'number' not found.
我有number列,我可以在MySQL Workbench中成功调用存储过程。