我想比较从表单中获取的字符串与带有表值的值......但是有空指针异常
2)我如何让结果集不访问表的最后一条记录
String occid = request.getParameter("occid");
String date = request.getParameter("Date");
String firstname = request.getParameter("FirstName");
String lastname = request.getParameter("LastName");
String village = request.getParameter("Village");
String sonof = request.getParameter("Son");
String district = request.getParameter("District");
String weight = request.getParameter("Weight");
String bags = request.getParameter("Bags");
String rate = request.getParameter("Rate");
String amount = request.getParameter("Amount");
String advanceamt = request.getParameter("Advance");
String sql = null;
PreparedStatement prest = null;
List<AcceptBean> list = new ArrayList<AcceptBean>();
sql = "Select * from ColdStorage.OccupantMaster";
prest = conn.prepareStatement(sql);
ResultSet rs = prest.executeQuery();
String first = "";
String last = "";
String vill = "";
String son = "";
String dist = "";
while (rs.next()) {
AcceptBean bean = new AcceptBean();
first = rs.getString("FirstName");
bean.setFirstName(first);
System.out.println("first = " + first);
last = rs.getString("LastName");
bean.setLastName(last);
System.out.println("last = " + last);
vill = rs.getString("Village");
bean.setVillage(vill);
System.out.println("vill = " + vill);
son = rs.getString("Sonof");
bean.setSonOf(son);
System.out.println("son = " + son);
dist = rs.getString("District");
bean.setDistrict(dist);
System.out.println("dist = " + dist);
list.add(bean);
}
for (AcceptBean s : list) {
if ((first.equals(firstname) || first.equals("null")) && (last.equals(lastname) || last.equals("null")) &&
(vill.equals(village) || vill.equals("null")) && (son.equals(sonof) || son.equals("null")) &&
(dist.equals(district) || dist.equals("null")))
{
System.out.println("do nothing");
ServletContext sc = getServletContext();
RequestDispatcher rd = sc.getRequestDispatcher("/Index.jsp");
System.out.println("it exists in database");
rd.forward(request, response);
}
数据库值是 -
OccId 名 姓 村 SonOf 区
31 Sourodeep bag bengal aurobindo bad bengal
32 ARVINDBHAI 帕尔马萨乔德
第 67 章
72 urvashi parmar 孟买 arvindbhai parmar 孟买
90 迪扬 NULL NULL NULL NULL
91 迪扬 NULL NULL NULL NULL