我已经为此奋斗了好几个小时,就我快到了,我仍然完全没有。此页面通过查询链接以加载在前一页上选择的图片的特定信息记录。
如果我转到图片没有评分的链接,它将加载评分为 0 的页面没有问题。如果我单击我知道它有评分的页面,它会给我一个“找不到数据”异常。
if (session.getAttribute("loginOK") != "true") {
response.sendRedirect("index.jsp");
}
String id = request.getParameter("photoid");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn = DriverManager.getConnection("jdbc:odbc:GalleryDB", "", "");
Statement st = cn.createStatement();
ResultSet r = st.executeQuery("SELECT AVG(rating) AS aRating, FileName, Title, Date, Location, Description FROM Photo LEFT JOIN Rating ON Photo.PhotoID = Rating.PhotoID WHERE Photo.PhotoID = " + id + " GROUP BY Rating.PhotoID, FileName, Title, Date, Location, Description;");
String html = "";
String image = "";
while (r.next()) {
image += "<img align='right' src='images/" + r.getString("FileName") + "'/>";
html += "Title: " + (r.getString("Title") + "</br></br>");
html += "Date: " + (r.getString("Date") + "</br></br>");
html += "Location: " + (r.getString("Location") + "</br></br>");
html += "Description: " + (r.getString("Description") + "</br></br>");
if (r.getString("aRating") != null) {
html += "Rating: " + (r.getString("aRating"));
} else {
html += "0";
}
}
cn.close();
任何人都可以就为什么会发生这种情况提供任何建议吗?