你好,我收到了这些页面:
DistributieFilm.java
包裹filme;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class DistributieFilm {
public static ArrayList<Film> getFilme() {
ArrayList<Film> listaFilm = new ArrayList<Film>();
PreparedStatement stm = null;
ResultSet rs = null;
Connection conn = null;
String query = "SELECT * FROM imdbutil.filme WHERE film_nume=?";
try {
conn = DbUtil.getConnection();
stm = conn.prepareStatement(query);
rs = stm.executeQuery();
while (rs.next()) {
Film lista = new Film();
lista.setId(rs.getInt("film_id"));
lista.setNume(rs.getString("film_nume"));
lista.setRegizor(rs.getString("film_regizor"));
lista.setDatalansarii(rs.getString("film_datalansarii"));
listaFilm.add(lista);
}
} catch (SQLException e) {
//
System.out.println(e.getMessage());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DbUtil.closeAll(rs, stm, conn);
}
return listaFilm;
}
}
Film.class
package filme;
public class Film {
private int film_id;
private String film_nume;
private String film_regizor;
private String film_datalansarii;
public Film(String nume, String regizor, String datalansarii) {
this.film_nume = nume;
this.film_regizor = regizor;
this.film_datalansarii = datalansarii;
}
public Film() {
// TODO Auto-generated constructor stub
}
public int getId() {
return film_id;
}
public String getNume() {
return film_nume;
}
public String getRegizor() {
return film_regizor;
}
public String getDatalansarii() {
return film_datalansarii;
}
public void setId(int id) {
this.film_id = id;
}
public void setNume(String nume) {
this.film_nume = nume;
}
public void setRegizor(String regizor) {
this.film_regizor = regizor;
}
public void setDatalansarii(String datalansarii) {
this.film_datalansarii = datalansarii;
}
}
和cautare.jsp
<%@page import="java.util.*"%>
<%@page import="filme.*"%>
<%@page import="java.sql.*"%>
<html>
<body>
<%
Film filmNoua = new Film(request.getParameter("film_nume"),request.getParameter("film_regizor"),request.getParameter("film_datalansarii"));
ArrayList<Film> listaFilm = DistributieFilm.getFilme();
%>
<center>
<table border="1">
<tr>
</tr>
<tr>
<td><b><font color="#ffffff">Id</td></font>
<td><b><font color="#ffffff">Nume</td></font>
<td><b><font color="#ffffff">Regizor</td></font>
<td><b><font color="#ffffff">Data Lansarii</td></font>
</tr>
<%
for (Film lista : listaFilm) {
%>
<tr>
<td><font color="#ff0000"><%=lista.getId()%></td></font>
<td><font color="#ff99ff"><%=lista.getNume()%></td></font>
<td><font color="#bb0fff"><%=lista.getRegizor()%></td></font>
<td><font color="#ffggff"><%=lista.getDatalansarii()%></td></font>
</tr>
<%
}
%>
<tr>
<td><a href="inserare.jsp"><input type="button" value="Insereaza un nou film"></a></td>
<tr>
</table>
</center>
</body>
</html>
我的问题是,我如何能够通过名称搜索我在数据库中获得的电影(我有5部电影,我想搜索1并显示它.ps我有一个search.jsp,我在那里添加一个文本字搜索)
由于
答案 0 :(得分:1)
您必须将过滤条件传递给DAO类DistributieFilm
;修改getFilme
以接受filmNoua
作为参数。
将标准设置为您的陈述
stm.setString(1, filmNoua.getName());
rs = stm.executeQuery();