sqlserver数据库取返回值(字符串类型)
存储过程定义
ALTER PROCEDURE test1
@num varchar(100)
AS
BEGIN
return '222字符333';
END
CallableStatement cStmt
存储过程调用 {call test1(20)}
参数注册 cStmt.registerOutParameter(1, Types.VARCHAR);
取返回值 cStmt.getString(1);
return的如果只纯数字就没错 ,如果是 带有字母,或者数字就有错:
com.microsoft.sqlserver.jdbc.SQLServerException: 在将 varchar 值 'sdfsgsf' 转换成数据类型 int 时失败。
at com.microsoft.sqlserver.jdbc.
SQLServerException.makeFromDatabaseError(SQL
ServerException.java:156)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1373)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:371)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:322)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4003)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1550)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:160)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:133)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(SQLServerPreparedStatement.java:304)
at dzhdb.test.commons.dao.DAOAutoTest.spExecuteRun(DAOAutoTest.java:1264)
at dzhdb.test.web.autotest.TestThread.run(TestThread.java:34)
at java.lang.Thread.run(Unknown Source)
------解决方案--------------------
com.microsoft.sqlserver.jdbc.SQLServerException: 在将 varchar 值 'sdfsgsf' 转换成数据类型 int 时失败。
at 这句话不是很清楚的