我想比较取自表格的字符串与具有表值的值...但是有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
名字
姓
村
的儿子
区
31
深渊
袋
孟加拉
坏蛋
孟加拉
32
阿文拜
帕玛
萨约德
巴拉比海
萨约德
67
divyang
帕尔马
巴鲁
Arvindbhai
巴鲁
72
urvashi
帕尔马
孟买
Arvindbhai Parmar
孟买
90
divyang
空值
空值
空值
空值
91
divyang
空值
空值
空值
空值
最佳答案
您必须检查是否为空
如果(第一!=空)
2.如果为空,则null
不等于NULL
,因为您使用过equals,请使用equalsIgnoreCase代替。