0
と仮定1つのレコードのみが表示されている、私はCAT、CAMEL ,, CAPを持って、それが一つのレコードではないすべてのレコードを表示しています。データベース内検索IDに基づいて複数のレコードを取得できません。私は「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;
}
:他のJSPで
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");
}
、私は「apname」のキーワードを渡すと、リストを使用して他のJSPページ内のレコードを表示する表示してセッションを渡していますサーブレットクラスから
しかし、出力では、1つのレコードのみが表示されています。あなたは結果を読んでいる間、あなたはif(rs.next())
を使用している、まあこの
私はまだ1つだけのレコード – Muskan
を同じ取得し、しばらく(rs.nextを())を使用し、あなたが正しくあなたのメソッドを呼び出していますか? – Shirkam