Go4Expert

Go4Expert (http://www.go4expert.com/)
-   JSP (http://www.go4expert.com/forums/jsp/)
-   -   JSP-MYSQL Problem with where condition (http://www.go4expert.com/forums/jsp-mysql-condition-t26830/)

yaswanth 2Oct2011 01:25

JSP-MYSQL Problem with where condition
 
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...

salam Muhammed 8Oct2011 12:40

Re: JSP-MYSQL Problem with where condition
 
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 +"'";


All times are GMT +5.5. The time now is 15:17.