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
...
我与这个麻烦从程序获得罚球消息。我该如何解决这个问题?
还是有其他的方式来工作吗?请帮帮我。
谢谢。