What the hey does this MySql error message mean?java.sql.SQLException: boo!springframework.dao.TransientDataAccessResourceException: CallableStatementCallback; SQL [{call sp_MyStoredProc(?, ?, ?)}]; boo!It's not particularly meaningful that's for sure. Has anybody come across this and is able to translate to less lazy~developer~ish...?I am accessing via org.springframework.jdbc.object.StoredProcedure I am using org.springframework.jdbc-3.1.3@UpdateThe offending lines are in CallableStatetement.java (2269-2271)if (!found) { throw SQLError.createSQLException("boo!", "S1000", this.connection.getExceptionInterceptor());`}Attching the sources for mysql-connector-java-5.1.18.jar and tracing though the code reveal that the correct message should be along the lines of 'mismatch between declared and actual parameters' or similar.Indeed correctly declaring my output parameterdeclareParameter(new SqlOutParameter("output", Types.INTEGER));rather thandeclareParameter(new SqlParameter("output", Types.INTEGER));fixed my problem. But a more meaningful error message would have saved precious time. I shall make this suggestion to the MySql Connector/J Development team. 解决方案 As stated in the update to the question this is commonly caused by incorrectly using a CallableStatement. For example:Stored Procedure uses 2 parameters, one in and one out:CREATE DEFINER=`example`@`localhost` PROCEDURE `sp_getSensorLocation`(IN in_id VARCHAR(128), OUT loc VARCHAR(128))BEGINSELECT LOCATION INTO loc FROM table.SENSORSWHERE ID = in_id;ENDbut the call to it only uses 1:private String getSensorLocation(String sensorID) { String location = ""; Connection c = dbr.getConnection(); String prepStatement = "{ call sp_getSensorLocation(?) } "; try { callableStatement cs = c.prepareCall(prepStatement); cs.setString(1, sensorID); ResultSet rs = cs.executeQuery(); if (rs.next()) { location = rs.getString(1); } } catch (SQLException ex) { LOG.error("Error:", ex); } dbr.closeConnection(c, rs, cs); return location;}When the correct code is really:private String getSensorLocation(String sensorID) { String location = ""; Connection c = dbr.getConnection(); String prepStatement = "{ call sp_getSensorLocation(?, ?) } "; try { CallableStatement cs = c.prepareCall(prepStatement); cs.setString(1, sensorID); cs.execute(); location = cs.getString(2); } catch (SQLException ex) { LOG.error("Error:", ex); } dbr.closeConnection(c, rs, cs); return location;}Notice I also changed to cs.execute as I don't expect a result set and would have issues with this as well (the example is taken from someone else's code I'm fixing, the joys -_-) 这篇关于晦涩的MySql Connector/J错误消息-java.sql.SQLException:boo {感叹号}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-03 03:11