【发布时间】:2016-12-11 11:43:44
【问题描述】:
假设在我的表中,我有 CAT、CAMEL、CAP 当我按“CA”搜索时,它显示的是一条记录而不是所有记录。
在数据库中:
public List<Application> getAllapplicationDetails(String name)
{
List<Application> app=new ArrayList<Application>();
try
{
Connection con = null;
String dbUrl = "jdbc:oracle:thin:@localhost:1521:XE";
System.out.println("1 step");
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("2 step");
con = DriverManager.getConnection (dbUrl, "system", "system");
System.out.println("3 step");
PreparedStatement ps = con.prepareStatement("select * from Application where LOWER(name) like '"+ name.toLowerCase()+"%'");
System.out.println("Entering in to the fucntion 2");
ps.execute();
System.out.println("Entering in to the fucntion 13");
ResultSet rs =ps.getResultSet();
if(rs.next())
{
System.out.println("Entering in to the fucntion 4");
Application abean=new Application();
abean.setName(rs.getString(1));
abean.setApplicationName(rs.getString(2));
abean.setContactNumber(rs.getInt(3));
app.add(abean);
System.out.println("Entering in to the fucntion 1" + app);
}
}
catch(SQLException e)
{
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return app;
}
在 servlet 中:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
DBConnection db=new DBConnection();
HttpSession hs = request.getSession();
String name=request.getParameter("appname");
List<Details> dbean=db.getAllDetails(name);
hs.setAttribute("detbean",dbean);
if(dbean.isEmpty())
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.print("<caption>Sorry, No Record Found</caption>");
}
else
response.sendRedirect("Application.jsp");
}
在其他 jsp 中,我正在显示传递“apname”关键字并使用列表并通过从 servlet 类传递会话在其他 jsp 页面中显示记录
但在 output 中,它只显示一条记录。请帮我解决这个问题
【问题讨论】:
标签: java