我的SP: ALTER proc SP_test (@OutputX varchar(100) Output) as DECLARE @f1 varchar(100) DECLARE xCursor CURSOR FOR SELECT re FROM tree OPEN xCursor FETCH xCursor into @F1 WHILE @@FETCH_STATUS = 0 BEGIN set @OutputX = @OutputX + isnull(@F1,'') FETCH NEXT FROM xCursor into @F1 END CLOSE xCursor DEALLOCATE xCursor set @OutputX = 'hello:' + isnull(@OutputX,'Null') select 1
http://www.microsoft.com/downloads/details.aspx?FamilyID=4f8f2f01-1ed7-4c4d-8f7b-3d47969e66ae&DisplayLang=en请在你的SP的最后加一句:
select 1
--===============
试试我的jsp
<!-- test.jsp -->
<%@ page contentType ="text/html;charset=gb2312" %>
<%@ page import="java.util.*;" %>
<HTML>
<HEAD>
</HEAD>
<BODY>
<%
java.lang.Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
java.sql.Connection ConnectionX = java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://TRIATON\\PSQL2KE;DatabaseName=tree","sa","");
java.sql.CallableStatement CallableStatementX = ConnectionX.prepareCall("{call sp_test (?)}");
CallableStatementX.setString(1,"bill");
CallableStatementX.registerOutParameter(1,java.sql.Types.VARCHAR);
CallableStatementX.executeQuery();
%>
<%= CallableStatementX.getString(1)%>
</BODY>
</HTML>
ALTER proc SP_test
(@OutputX varchar(100) Output)
as
DECLARE @f1 varchar(100)
DECLARE xCursor CURSOR
FOR SELECT re FROM tree
OPEN xCursor
FETCH xCursor into @F1
WHILE @@FETCH_STATUS = 0
BEGIN
set @OutputX = @OutputX + isnull(@F1,'')
FETCH NEXT FROM xCursor into @F1
END
CLOSE xCursor
DEALLOCATE xCursor
set @OutputX = 'hello:' + isnull(@OutputX,'Null')
select 1
{
public static void main(String[] args) throws java.sql.SQLException
{
try
{
java.lang.Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch (java.lang.ClassNotFoundException e1)
{
System.err.print("ClassNotFoundException: ");
System.err.println(e1.getMessage());
}
java.sql.Connection ConnectionX = java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://TRIATON\\PSQL2KE;DatabaseName=tree","sa","");
java.sql.CallableStatement CallableStatementX = ConnectionX.prepareCall("{call sp_test (?)}");
CallableStatementX.setString(1,"bill");
CallableStatementX.registerOutParameter(1,java.sql.Types.VARCHAR);
CallableStatementX.executeQuery();
System.out.print(CallableStatementX.getString(1));
System.out.print("End");
}
}
select 1