MS SQL Server 2005 通用分页存储过程


package cn.com.aweb.vote.test.conndbUtil;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class TestCunChu2 {

/**
* @param args
*/

public static void main(String[] args) throws SQLException{
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
String url =
"jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test;user=test;password=123456";
try {
Class.forName(
"com.microsoft.sqlserver.jdbc.SQLServerDriver");//1295
con = DriverManager.getConnection(url);
//exec Pagination 1,2,'admin','*','id asc','',@maxPage,@totalRow,@descript
CallableStatement cstmt = con.prepareCall(
"{call dbo.Pagination(?,?,?,?,?,?,?,?,?)}");
cstmt.setInt(1, 1);
cstmt.setInt(2, 3);
cstmt.setString(3,
"admin");
cstmt.setString(4,
"*");
cstmt.setString(5,
"id asc");
cstmt.setString(6,
"");
cstmt.registerOutParameter(7, java.sql.Types.INTEGER);
cstmt.registerOutParameter(8, java.sql.Types.INTEGER);
cstmt.registerOutParameter(9, java.sql.Types.VARCHAR);
cstmt.execute();
System.out.println(
"maxPage: " + cstmt.getInt(7));
System.out.println(
"@TotalRow: " + cstmt.getInt(8));
System.out.println(
"@Descript: " + cstmt.getString(9));
rs = cstmt.executeQuery();
int i = 0;
while(rs.next()){
i++;
System.out.println(rs.getString(
"admin_name"));
}
System.out.println(
"i="+i);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (con != null) {
con.close();
}
if (stmt != null) {
stmt.close();
}
if (rs != null) {
rs.close();
}
}

}

}


}

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

认证码:
(数字如不清楚,请刷新一次)


Copyright@2004-2010 powered by YuLog