JSP-MYSQL Problem with where condition

Discussion in 'JSP' started by yaswanth, Oct 1, 2011.

  1. yaswanth

    yaswanth New Member

    Joined:
    Oct 1, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student.B.Tech
    Location:
    Vijayawada
    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 a moderator: Oct 2, 2011
  2. salam Muhammed

    salam Muhammed New Member

    Joined:
    Oct 8, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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 +"'";
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice