사용자가 범주, 제목 또는 출시 날짜로 검색 할 수있는 검색 양식을 사용하여 영화 컬렉션을 탐색 할 수있는 JSP 페이지에서 작업하고 있습니다. 검색 조건이 없으면 모든 영화가 표시되어야합니다. 내 문제는 그게 * 작품의 출시 연도별로 검색이 잘 작동하지만 제목이 작동하지 않고 검색 결과가 전혀 표시되지 않는다는 것입니다. * 제목을 검색 할 때 연말 검색에 넣을 때 작동하지 않습니다. 작품 및 그 반대로jsp에서 검색을 사용하는 중에 오류가 발생했습니다.
<%
String s1 = request.getParameter("Ttl");
String s2 = request.getParameter("Yr");
out.println("<TABLE >");
out.println("<TR>");
out.println("<TH>Category</TH>");
out.println("<TH>Title</TH>");
out.println("<TH>Release Year</TH>");
out.println("<TH>Rental Price</TH>");
out.println(" <TH></TH>");
out.println("<TH></TH>");
out.println(" </TR>");
String sql = //search if no search condition
"SELECT *" +
" FROM users" +
" WHERE ";
if (s1!=null && !(s1.equals(""))){ //search by title
sql = sql +
"title LIKE '%" +
s1 + "%'";
}
if (s2!=null){ //search by year
sql = sql +
" year LIKE '%" +
s2 + "%'";
}
try{
Connection con =
DriverManager.getConnection("jdbc:odbc:UsersData");
System.out.println("got connection");
Statement s = con.createStatement();
ResultSet rs = s.executeQuery(sql);
while (rs.next()) {
out.println("<TR>");
String id = rs.getString(5);
out.println("<TD>" + rs.getString(1) + "</TD>");
out.println("<TD>" + rs.getString(2) + "</TD>");
out.println("<TD>" + rs.getString(3) + "</TD>");
out.println("<TD>" + rs.getString(4) + "</TD>");
out.println("<TD><A HREF=Add to shoping cart?id=" + id + ">Add to shoping cart</A></TD>");
out.println("</TR>");
}
s.close();
con.close();
}
catch (SQLException e) {
}
catch (Exception e) {
}
%>
제안 : SQL 문자열을 출력하고 "작동중인"대 "작동하지 않는"대 비교하십시오. – paulsm4
Eeeew, scriptlets, 심지어 테이블 물건?! 왝. –