[英]Java code for Getting data from two tables
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. 您在
rs.next()
周围有一个循环-它将为其中的每个记录重复一次。
Inside that you're looking at r.next()
- how many will this be? 在里面,您正在查看
r.next()
-这将是多少?
If they don't match up exactly, then you're going to have problems accessing your data. 如果它们不完全匹配,那么访问数据将遇到问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.