1.建立SQL Server存储过程
CREATE PROCEDURE prepareStatementEND 2.在SQL Server中测试存储过程
@USR_CODE varchar(128)
AS
BEGIN
select * from [user] u where u.[USR_CODE]=@USR_CODE
EXEC prepareStatement 'test'
3.Java代码
public List<Role> getRoleByUserCode(String userCode){
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
List<Role> list = new ArrayList<Role>();
try {
conn = dataSource.getConnection();
//ps = conn.prepareStatement("select * from [user] u where u.[USR_CODE]=?");
ps = conn.prepareStatement("{call dbo.prepareStatement(?)}");
ps.setString(1, userCode);
rs = ps.executeQuery();
以上
但愿诸兄看明白了..
参考文章:
2.SqlServer中存储过程中将Exec的执行结果赋值给变量输出