1. 程式人生 > >數據分頁查找心得總結

數據分頁查找心得總結

sta 技術 rom red let rac 分享圖片 dst 傳遞數據

1,request.getParamter()是返回String類型,而request.setAtrribute()是返回Object類型的,想要將Object類型 a 轉換為String類型 String b = a.toString().

2,為了防止報空指針 所以接收的數據進行判斷的時候都要放在equals()內。比如message!=null&&!"".equals(message).

3,表單傳輸時一定要有method方法不然根本沒有辦法傳輸出去。

4,使用技術分享圖片方法傳遞數據到servlet中,servlet返回到界面時,一定要註意路徑,路徑必須是從目錄出發的。

5,統計數據庫表中的數據條數 select count(*)as totalCount from demand_form 具體JavaBean代碼如下:

/**
* 統計數據庫中數據的總數
*/
public int total() {
int total = 0;
Connection con = connect.getCon();
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = con.prepareStatement("select count(*)as totalCount from demand_form");

rs = pstmt.executeQuery();
if(rs.next()) {
total = rs.getInt("totalCount");
}
} catch (SQLException e) {
// TODO 自動生成的 catch 塊
connect.close(rs,pstmt, con);
}
return total;
}

按時間段查找數據 以及數據條數 select*from demand_form where date between ‘2019-03-05‘ and ‘2019-03-06‘ limit 0,5;

select count(*)as totalCount from demand_form where date between ‘2019-03-05‘ and ‘2019-03-06‘;

具體Javabean代碼

/**
* 按時間段查找需求表單
*/
public ArrayList<demand> queryTimedemand(String date1,String date2,int a){
Connection con = connect.getCon();
ArrayList<demand> list = new ArrayList<>();
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = con.prepareStatement("SELECT*FROM demand_form where date BETWEEN ‘"+date1+"‘ and ‘"+date2+"‘ limit "+a*5+","+(a+1)*5);
rs = pstmt.executeQuery();
while (rs.next()) {
demand dem = new demand();
dem.Set(rs.getString(1), rs.getString(2), rs.getString(3).split("&"), rs.getString(4), rs.getDouble(5), rs.getString(6),rs.getString(7),rs.getString(8));
dem.setPass(rs.getString(9));
list.add(dem);
}
return list;
} catch (SQLException e) {
// TODO 自動生成的 catch 塊
e.printStackTrace();
return null;
} finally {
connect.close(rs,pstmt, con);
}

}

/**
* 按時間段統計表單數據條
*/
public int Timetotal(String date1,String date2) {
int total = 0;
Connection con = connect.getCon();
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = con.prepareStatement("select count(*)as totalCount from demand_form where date BETWEEN ‘"+date1+"‘ and ‘"+date2+"‘");
rs = pstmt.executeQuery();
if(rs.next()) {
total = rs.getInt("totalCount");
}
} catch (SQLException e) {
// TODO 自動生成的 catch 塊
connect.close(rs,pstmt, con);
}
return total;
}

數據分頁查找心得總結