フォームから取得した文字列とテーブルの値を比較したいのですが、nullpointerexception があります
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 FirstName LastName Village SonOf District
31 Sourodeep バッグ ベンガル オーロビンド 悪いベンガル
32 ARVINDBHAI PARMAR SAJOD パラグバイ サジョード
67 divyang parmar bharuch Arvindbhai bharuch
72 urvashi parmar ムンバイ arvindbhai parmar ムンバイ
90 divyang NULL NULL NULL NULL
91 divyang NULL NULL NULL NULL