title: sql statement not working in jsp
body: <p>This is the Code i have , I think its the Sql string that is not working correctly. im able to view the table and cick on the edit field but im only able to update the first row. i want to be able to select a row and than edit it according to its id . </p>
  
  <pre><code>//Database View
  &lt;%@ page import="java.sql.ResultSet" %&gt;
  &lt;%@ page import="java.sql.SQLException" %&gt;
  &lt;%@ page import="java.sql.Statement" %&gt;
  &lt;%@ page import="java.sql.Connection" %&gt;
  &lt;%@ page import="java.sql.DriverManager" %&gt;
  
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Inventory&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;%
      Connection connect = null;
      Statement s = null;
  
      try {
          Class.forName("com.mysql.jdbc.Driver");
  
          connect =  DriverManager.getConnection("jdbc:mysql://localhost/client", "rootroot", "rootroot");
  
          s = connect.createStatement();
  
          String sql = "SELECT * FROM  client ORDER BY id ASC";
  
          ResultSet rec = s.executeQuery(sql);
          %&gt;
          &lt;table width="600" border="1"&gt;
            &lt;tr&gt;
              &lt;th width="91"&gt; &lt;div align="center"&gt;id &lt;/div&gt;&lt;/th&gt;
              &lt;th width="198"&gt; &lt;div align="center"&gt;Email &lt;/div&gt;&lt;/th&gt;
              &lt;th width="97"&gt; &lt;div align="center"&gt;CountryCode &lt;/div&gt;&lt;/th&gt;
              &lt;th width="59"&gt; &lt;div align="center"&gt;Budget &lt;/div&gt;&lt;/th&gt;
              &lt;th width="71"&gt; &lt;div align="center"&gt;Edit &lt;/div&gt;&lt;/th&gt;
            &lt;/tr&gt; 
              &lt;%while((rec!=null) &amp;&amp; (rec.next())) { %&gt;
                    &lt;tr&gt;
                      &lt;td&gt;&lt;div align="center"&gt;&lt;%=rec.getString("id")%&gt;&lt;/div&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;%=rec.getString("first_name")%&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;%=rec.getString("last_name")%&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;div align="center"&gt;&lt;%=rec.getString("blood_type")%&gt;&lt;/div&gt;&lt;/td&gt;
                      &lt;td align="right"&gt;&lt;%=rec.getString("gender")%&gt;&lt;/td&gt;
  
                      &lt;td align="center"&gt; &lt;a href="editpage.jsp?id=&lt;%=rec.getString("id")%&gt;"&gt;Edit&lt;/a&gt;&lt;/td&gt;
                    &lt;/tr&gt;
              &lt;%}%&gt;
          &lt;/table&gt;      
          &lt;%  
          } catch (Exception e) {
              // TODO Auto-generated catch block
              out.println(e.getMessage());
              e.printStackTrace();
          }
  
          try {
              if(s!=null){
                  s.close();
                  connect.close();
              }
          } catch (SQLException e) {
              // TODO Auto-generated catch block
              out.println(e.getMessage());
              e.printStackTrace();
          }
      %&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  //Edit Page 
  &lt;%@ page import="java.sql.ResultSet" %&gt;
  &lt;%@ page import="java.sql.SQLException" %&gt;
  &lt;%@ page import="java.sql.Statement" %&gt;
  &lt;%@ page import="java.sql.Connection" %&gt;
  &lt;%@ page import="java.sql.DriverManager" %&gt;
  
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;ThaiCreate.Com JSP Tutorial&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;%  
      Connection connect = null;
      Statement s = null;
  
      try {
          Class.forName("com.mysql.jdbc.Driver");
  
          connect =  DriverManager.getConnection("jdbc:mysql://localhost/client", "rootroot", "rootroot");
  
          s = connect.createStatement();
  
          String sql ="SELECT * FROM client";
  
          ResultSet rec = s.executeQuery(sql);
          if(rec != null) {
              rec.next();
          %&gt;
      &lt;form name="frmUpdate" method="post" action="SaveEdit.jsp?id=&lt;%=rec.getString("id")%&gt;"&gt; 
          Update Form
              &lt;table width="428" border="1"&gt;  
              &lt;tr&gt;
                  &lt;th width="181"&gt;
                  &lt;div align="left"&gt;Product ID &lt;/div&gt;&lt;/th&gt;
                  &lt;td width="231"&gt;&lt;%=rec.getString("id")%&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;th width="181"&gt;
                  &lt;div align="left"&gt;Name &lt;/div&gt;&lt;/th&gt;
                  &lt;td&gt;&lt;input type="text" name="txtName" size="20" value="&lt;%=rec.getString("first_name")%&gt;"&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;th width="181"&gt;
                  &lt;div align="left"&gt;Email &lt;/div&gt;&lt;/th&gt;
                  &lt;td&gt;&lt;input type="text" name="txtEmail" size="20" value="&lt;%=rec.getString("last_name")%&gt;"&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;th width="181"&gt;
                  &lt;div align="left"&gt;CountryCode &lt;/div&gt;&lt;/th&gt;
                  &lt;td&gt;&lt;input type="text" name="txtCountryCode" size="2" value="&lt;%=rec.getString("blood_type")%&gt;"&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;th width="181"&gt;
                  &lt;div align="left"&gt;Budget &lt;/div&gt;&lt;/th&gt;
                  &lt;td&gt;&lt;input type="text" name="txtBudget" size="5" value="&lt;%=rec.getString("gender")%&gt;"&gt;&lt;/td&gt;
              &lt;/tr&gt;
  
              &lt;/table&gt; 
          &lt;input type="submit" value="Save"&gt;
          &lt;/form&gt; 
  
          &lt;% }
  
          } catch (Exception e) {
              // TODO Auto-generated catch block
              out.println(e.getMessage());
              e.printStackTrace();
          }
  
          try {
              if(s!=null){
                  s.close();
                  connect.close();
              }
          } catch (SQLException e) {
              // TODO Auto-generated catch block
              out.println(e.getMessage());
              e.printStackTrace();
          }
      %&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  // save page 
  &lt;%@ page import="java.sql.ResultSet" %&gt;
  &lt;%@ page import="java.sql.SQLException" %&gt;
  &lt;%@ page import="java.sql.Statement" %&gt;
  &lt;%@ page import="java.sql.Connection" %&gt;
  &lt;%@ page import="java.sql.DriverManager" %&gt;
  
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Hello World&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;%  
      Connection connect = null;
      Statement s = null;
  
      try {
          Class.forName("com.mysql.jdbc.Driver");
  
          connect =  DriverManager.getConnection("jdbc:mysql://localhost/client", "rootroot", "rootroot");
  
          s = connect.createStatement();
  
          String strCustomerID = request.getParameter("id");
          String strName = request.getParameter("txtName");
          String strEmail = request.getParameter("txtEmail");
          String strCountryCode = request.getParameter("txtCountryCode");
          String strBudget = request.getParameter("txtBudget");
  
  
  
          String sql = "UPDATE client " +
                  "SET first_name = '"+ strName + "' " +
                  ", last_name = '"+ strEmail + "' " +
                  ", blood_type = '"+ strCountryCode + "' " +
                  ", gender = '"+ strBudget + "' " +
  
                  " WHERE id = '" + strCustomerID + "' ";
           s.execute(sql);
  
           out.println("Record Update Successfully");
  
          } catch (Exception e) {
              // TODO Auto-generated catch block
              out.println(e.getMessage());
              e.printStackTrace();
          }
  
          try {
              if(s!=null){
                  s.close();
                  connect.close();
              }
          } catch (SQLException e) {
              // TODO Auto-generated catch block
              out.println(e.getMessage());
              e.printStackTrace();
          }
      %&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>