String pnumber = request.getParameter("pnumber");
ResultSet rs = DAO.fetch("SELECT * FROM Products Where ProductNumber ='" + pnumber + "'");
ResultSet r = DAO.fetch("SELECT * FROM ExpensiveProducts");
Here I am getting data from a database:
try {
int v = Integer.parseInt(pnumber);
if (pnumber.length() == 7) {
Data not passing going this condition?
while (rs.next()) {
String pn = rs.getString(3);
String pqty = rs.getString(4);
int qty = Integer.parseInt(pqty);
if (pn.equals(pnumber)) {
if (qty > 0) {
response.sendRedirect("Status.jsp?Status=Available");
} else {
response.sendRedirect("Status.jsp?Status=Not Available");
}
} else {
while (r.next()) {
String epn = r.getString(3);
String epp = r.getString(4);
out.print(pnumber);
out.print(epn);
if (epn.equals(pnumber)) {
response.sendRedirect("Status.jsp?Status=EAvailable");
} else {
response.sendRedirect("Status.jsp?Status=E NAvailable");
}
}
response.sendRedirect("Status.jsp?Status=Product number not exist");
}
}
} else {
response.sendRedirect("Status.jsp?Status=test");
}
You have a loop around
rs.next()– this will iterate once for each record in it.Inside that you’re looking at
r.next()– how many will this be?If they don’t match up exactly, then you’re going to have problems accessing your data.