jsp - Fetch Multiple Records from Mysql Database Using Where Clause -
im using web application ,which runs on apache tomcat , has mysql database backend
i want retrieve multiple rows particular column usin clause
for example if give select * xyz type=abc
i should rows having type abc.
problem:
i use jdbc connection achieve this, 1st row matching condition returned rather rows (even though multiple rows match criteria in database)
kindly me resolve this
code:
<%@ page import="java.sql.*" %> <html> <head><link href="style.css" rel ="stylesheet" type="text/css"></head> <body bgcolor="white" > <div id="container"> <div id="header"> <img src="logo.jpg"> <div class ="horiztext"><p> order tracker</p></div> </div> </div> <br> <img src="banner.jpg" width="1500 " height="5"><br> <% if(session.getattribute("username") !=null) { %> <div id="navbar"> <ul> <li><a href="newoder.jsp">new order</a></li> <li><a href="updateorder.jsp">update order</a></li> <li><a href="trackorder.jsp">track order</a></li> <li><a href="trackdelay.jsp">track delay</a></li> <li><a href="vieworder.jsp">view database</a></li> <li><a href="delete.jsp">delete order</a></li> <li><a href="logout.jsp">logout</a></li> </ul> </div> <br> <br> <form> <table cellpadding="15" border="1" style="background-color: #ffffcc;"> <% string productnamez=request.getparameter("productname"); class.forname("com.mysql.jdbc.driver").newinstance(); connection conn = drivermanager.getconnection("jdbc:mysql://localhost:3307 /test","root", "root"); statement st=conn.createstatement(); resultset rs = st.executequery("select * inventory productname = '"+ productnamez +"' "); if(rs.next()){ %> <tr> <tr><th>serial no</th> <th>product name</th> <th>product type</th> <th>model</th> <th>make</th> <th>license / voucher</th> <th>location</th> </tr> <tr> <td><%=rs.getstring(1)%></td> <td><%=rs.getstring(2)%></td> <td><%=rs.getstring(3)%></td> <td><%=rs.getstring(4)%></td> <td><%=rs.getstring(5)%></td> <td><%=rs.getstring(6)%></td> <td><%=rs.getstring(7)%></td> </tr> <% } %> </table> </form> <% } else { %> not logged in click here <a href="eric.jsp"><b>login</b></a> <% } %> </body> </html>
you'll wanting
while (rs.next()){ instead of
if (rs.next()){
Comments
Post a Comment