下面是一个调用存储过程的方法:
public List<Authors> GetAllByProc(int targetpage, int pagesize) {
List<Authors> allauthors = new ArrayList<Authors>();
ResultSet rs = null;
Connection con = this.GetCon();
PreparedStatement ps = null;
CallableStatement cs=null;
try {
/*ps = con.prepareStatement("{call CN5135_SP_Pagination(?,?,?,?)}");
ps.setString(1, "authors");
ps.setString(2, "au_id");
ps.setInt(3, targetpage);
ps.setInt(4, pagesize);
rs = ps.executeQuery();
*/
cs=con.prepareCall("{call CN5135_SP_Pagination(?,?,?,?)}");
cs.setString("Tables", "authors");
cs.setString("PrimaryKey", "au_id");
cs.setInt("CurrentPage", targetpage);
cs.setInt("PageSize", pagesize);
rs=cs.executeQuery();
while (rs.next()) {
Authors newauthor = new Authors(rs.getString("au_id"), rs
.getString("au_lname"), rs.getString("au_fname"), rs
.getString("phone"), rs.getString("address"));
allauthors.add(newauthor);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("调用存储过程时出错");
e.printStackTrace();
} finally {
this.CloseAll(rs, ps, con,cs);
}
return allauthors;
}