我正在从java应用程序调用一个存储过程,使用CallableStatement
。我有许多其他的CallableStatements
采用完全相同的24字符作为输入,没有任何问题(在不同的表上)。
另外,当我在HeidiSQL中手动运行该过程并输入要保存的参数时,它会毫无问题地保存数据。
我试着用参数名称和索引设置CallableStatement
,没有成功。
整个错误:
java.sql.SQLException: cannot parse parameter definition :IN `device_id` CHAR(24)
at org.mariadb.jdbc.CallableParameterMetaData.readMetadata(MySQLCallableStatement.java:193)
at org.mariadb.jdbc.CallableParameterMetaData.readMetadataFromDBIfRequired(MySQLCallableStatement.java:63)
at org.mariadb.jdbc.CallableParameterMetaData.getParam(MySQLCallableStatement.java:237)
at org.mariadb.jdbc.CallableParameterMetaData.getName(MySQLCallableStatement.java:278)
at org.mariadb.jdbc.MySQLCallableStatement.nameToIndex(MySQLCallableStatement.java:493)
at org.mariadb.jdbc.MySQLCallableStatement.setString(MySQLCallableStatement.java:843)
at com.zaxxer.hikari.proxy.CallableStatementJavassistProxy.setString(CallableStatementJavassistProxy.java)
at com.app.data.DataDAO.saveBootloaderStateObject(DataDAO.java:222)
at com.app.firmware.server.UsartReconnectProcessor.processBytes(UsartReconnectProcessor.java:135)
at com.app.firmware.server.WorkerRunnable.run(WorkerRunnable.java:57)
at java.lang.Thread.run(Unknown Source)
我的代码:
public void saveBootloaderStateObject(
SavedBootloaderState bootloaderStateObject) {
Connection connection = null;
try {
connection = database.getConnection();
log.debug("DEVICE ID: " + bootloaderStateObject.getDeviceId());
CallableStatement callableStatement = connection
.prepareCall("{call saveBootloaderState(?,?,?,?,?,?,?,?)}");
callableStatement.setString("device_id", bootloaderStateObject.getDeviceId());
callableStatement.setString("current_state", bootloaderStateObject.getCurrentState());
callableStatement.setInt("current_position", bootloaderStateObject.getCurrentRecordPosition());
callableStatement.setString("build_date_new", bootloaderStateObject.getBuildDate());
callableStatement.setString("build_time_new", bootloaderStateObject.getBuildTime());
callableStatement.setString("build_date_old", "TODO");
callableStatement.setString("build_time_old", "TODO");
callableStatement.setObject("saved_bootloader_state", bootloaderStateObject, Types.BINARY);
} catch (SQLException e) {
log.info("An SQLException occured!", e);
closeDbConnection(connection);
}
}
存储过程:
BEGIN
INSERT INTO firmware_upgrade_recovery (device_id, current_state, current_position, build_date_new, build_time_new, build_date_old, build_time_old, saved_bootloader_state)
VALUES (current_state, current_position, build_date_new, build_time_new, build_date_old, build_time_old, saved_bootloader_state);
END
参数声明顺序相同,类型为CHAR
、VARCHAR
、INT
、VARCHAR
x4和BINARY
我从未正确解决过这个问题,我只是在输入参数中添加了'in'前缀。
所以device_id变成了in_device_id,以此类推。
这是我现在能做的最好的了。