日期:2014-05-18  浏览次数:20752 次

大家帮忙呀,JAVA加SQL SERVER存储过程编程,不会了
CREATE   PROCEDURE   ghy_proc_return   @max   int   output,@min   int   output
AS  
select   @max=max(job_id),@min=min(job_id)   from   jobs
GO


<%@   page   contentType= "text/html;charset=gb2312 "%>
<%@   page   import= "java.sql.* "%>
<html>
<body>
<%
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ")
.newInstance();
String   url   =   "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs ";
//pubs为你的数据库的
String   user   =   "sa ";
String   password   =   " ";
Connection   conn   =   DriverManager.getConnection(url,   user,   password);
//不带参数的存储过程
CallableStatement   stmt   =   conn
.prepareCall( "{call   ghy_proc_return} ");
stmt.registerOutParameter(1,   Types.INTEGER);
stmt.registerOutParameter(2,   Types.INTEGER);
stmt.execute();
ResultSet   rs   =   stmt.getResultSet();
while   (rs.next())   {
out.println( "max= "   +   rs.getInt(0));
out.println( "min= "   +   rs.getInt(1));
}

rs.close();
stmt.close();
%>
</body>
</html>


出错,帮忙哪块出错

------解决方案--------------------
<%@ page contentType= "text/html;charset=gb2312 "%>
<%@ page import= "java.sql.* "%>
<html>
<body>
<%
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ")
.newInstance();
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test ";
//pubs为你的数据库的
String user = "sa ";
String password = " ";
Connection conn = DriverManager.getConnection(url, user, password);
//不带参数的存储过程
CallableStatement cs = conn.prepareCall( "{call ghy_proc_return(?,?) } ");
cs.registerOutParameter(1, Types.INTEGER);
cs.registerOutParameter(2, Types.INTEGER);
cs.execute();
//注意下面的代码:(索引从1开始)
out.println( "max= " + cs.getInt(1));
out.println( "min= " + cs.getInt(2));
cs.close();
conn.close();
%>
</body>
</html>