0

I have a strange problem that i can call the MySQL stored procedure successfully. But calling it using Java returns an error.

Following is my Controller method:

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;
}

This is my stored procedure:

CREATE DEFINER=`root`@`localhost` PROCEDURE `getBalance`(IN string_number varchar(19))
BEGIN
select amount from wallet where number=string_number;
END

The error is:

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.

I have the number column and i can call the stored procedure in MySQL Workbench successfully.

1 Answer 1

1

You should use the doWork() function instead, you can basically create the connection with Lambda expressions. You can see a few examples HERE

Sign up to request clarification or add additional context in comments.

1 Comment

If you're not familiar with CallableStatement, you can search for documentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.