JSP-MYSQL Problem with where condition

Newbie Member
2Oct2011,01:25   #1
yaswanth's Avatar
Hello every one..plzz solve my problem

here iam specifying where condition in my jsp page but it doesnt work..
with out specifying where condition it displays all data in my table..

iam getting the problem with the where condition in the jsp with MYSQL


and code is..

Class.forName ("com.mysql.jdbc.Driver").newInstance ();
Code:
Connection con = DriverManager.getConnection(url, user, pass);
 Statement stmt=con.createStatement();
 String section=request.getParameter("section");
String QueryString = "SELECT * from students where section='"+section+"'";
		 
          rs = stmt.executeQuery(QueryString);
		  
%>
<TABLE cellpadding="5" border="1" style="background-color: #ffffcc;" align="center">
    <%
    while (rs.next()) {
    %>
	<TR>
	<TD>Regd No</TD>
	<TD>Name</TD>
	<TD>BRANCH</TD>
	</TR>
    <TR>
        
        <TD><%= rs.getString(1) %></TD>
        <TD><%= rs.getString(2) %></TD>
        <TD><%= rs.getString(3) %></TD>
		
    </TR>
	
    <%   }    %>
    <%
    // close all the connections.
    rs.close();
    stmt.close();
    con.close();
}
plzzz.....thanks in advance...

Last edited by shabbir; 2Oct2011 at 09:54.. Reason: Code blocks
Newbie Member
8Oct2011,12:40   #2
salam Muhammed's Avatar
You can solve this problem with the where condition in the jsp by putting spaces before and after the 'section' as given below
String QueryString = "SELECT * from students where section='"+ section +"'";