1
我正在使用Spring,MyBatis和Microsoft SQL Server。在我的項目中,我需要從MyBatis mapper xml文件中調用一個程序。MyBatis:從SQL Server捕獲消息拋出存儲過程
所以,我做到了像如下:
<select id="callProcedure" parameterType="TestBean" statementType="CALLABLE" >
{CALL callprocedure(#{id},#{regId})}
</select>
而且,這是運作良好。後來,我加入我的存儲過程THROW
報表如下圖所示:
THROW 50002, "Invalid Parameters", 1;
而且,我趕上異常在吾道Java類如下:
try {
myMapper.callProcedure(testBean);
} catch (Exception e) {
System.out.println(e.getMessage());
}
也就是說,存在的主要問題在這兒。當打印出來的信息時,它顯示了很多線條和原因。不僅是我所拋出的信息。我只想要我傳遞的信息。
我不能通過調用e.getMessage()
來獲得我從程序中拋出的消息。
這顯示以下信息:
org.springframework.jdbc.UncategorizedSQLException:
### Error querying database. Cause:com.microsoft.sqlserver.jdbc.SQLServerException: Invalid Parameters
### The error may exist in mybatis/mapper/application/test.xml
### The error may involve com.test.core.mapper.application.TestMapper.callProcedure-Inline
### The error occurred while setting parameters
### SQL: {CALL callprocedure(?,?)}
### Cause: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid Parameters; uncategorized SQLException for SQL []; SQL state [S0001]; error code [50002]; Invalid Parameters; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Invalid Parameters
...
我與這個麻煩從程序獲得罰球消息。我該如何解決這個問題?
還是有其他的方式來工作嗎?請幫幫我。
謝謝。