【发布时间】:2017-06-11 06:41:39
【问题描述】:
我的本地有Sakila Sample Database,我正在尝试从Java 调用get_customer_balance 函数。
这是我的代码:
double callableStatementFunctionCallExample(final int customerId) throws SQLException {
double customerBalance = -1;
final Connection connection = DriverManager.getConnection(url, user, pass);
final CallableStatement callableStatement = connection.prepareCall("{CALL ? = get_customer_balance(?, ?)}");
callableStatement.registerOutParameter(1, customerBalance);
callableStatement.setInt(2, customerId);
final java.sql.Date date = new Date(Calendar.getInstance().getTimeInMillis());
callableStatement.setDate(3, date);
callableStatement.execute();
return customerBalance;
}
导致:
Exception in thread "main" java.sql.SQLException: Parameter number 1 is not an OUT parameter.
所以我替换了这个语句..
callableStatement.registerOutParameter(1, customerBalance);
与..
callableStatement.setDouble(1, customerBalance);
导致:
Exception in thread "main" java.sql.SQLException: Parameter p_film_count is not registered as an output parameter.
很明显我需要注册一个out parameter,但是如何注册呢?为什么我的第一种方法是错误的?
【问题讨论】:
标签: java mysql stored-functions