title: Only Partial Data Returned from Database Using JSP Form
body: <p>I'm new to mysql and teaching myself the ropes.  I've come across a problem and hoping for some advice.</p>
  
  <p>I created a form in a jsp page to insert data to a mysql database.  All data is properly inserted, and when I do select* all data is properly displayed in a table I created.  My problem is with my  update page.  </p>
  
  <p>When I call data from the database back into a form on my editdata.jsp page, only everything before a space is returned.  For example, I put the name 'Tom Jones' into a database, but when I go to retrieve it from the name field, only 'Tom' is returned; 'Jones' is not, but is still there in the database.</p>
  
  <p>Here's my editdata.jsp code:</p>
  
  <pre><code>&lt;%@page import="java.sql.ResultSet"%&gt;
  &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
      &lt;title&gt;JSP Page&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form action ="UpdateData" method ="post"&gt;
      &lt;table border ="1" width="80%"&gt;
  
  
              &lt;%ResultSet res = (ResultSet) request.getAttribute("EditData");%&gt;
              &lt;%if(res.next()){
                  %&gt;
                  &lt;tr&gt;
                     &lt;td&gt;ID&lt;/td&gt;
                     &lt;td&gt;&lt;input type="text" name="id" value=&lt;%=res.getString("id")%&gt;&gt;   
  &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                     &lt;td&gt;Container Number &lt;/td&gt;
                     &lt;td&gt;&lt;input type="text" name="id" value=
  &lt;%=res.getString("containerNumber")%&gt; &gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                     &lt;td&gt;Size &lt;/td&gt;
                     &lt;td&gt;&lt;input type="text" name="id" value=&lt;%=res.getString("size")%&gt;&gt; 
   &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                     &lt;td&gt;Vessel &lt;/td&gt;
                     &lt;td&gt;&lt;input type="text" name="id" value=&lt;%=res.getString("vessel")%&gt;&gt; 
   &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                     &lt;td&gt;Full Out Date &lt;/td&gt;
                     &lt;td&gt;&lt;input type="text" name="id" value=
   &lt;%=res.getString("fullOut")%&gt;&gt; &lt;/td&gt;
                  &lt;/tr
                  &lt;tr&gt;
                     &lt;td&gt;Empty In Date &lt;/td&gt;
                     &lt;td&gt;&lt;input type="text" name="id" value=&lt;%=res.getString("emptyIn")%&gt;
   &gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                     &lt;td&gt;Empty Out Date &lt;/td&gt;
                     &lt;td&gt;&lt;input type="text" name="id" value=
  &lt;%=res.getString("emptyOut")%&gt;&gt; &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                     &lt;td&gt;Full In Date &lt;/td&gt;
                     &lt;td&gt;&lt;input type="text" name="id" value=&lt;%=res.getString("fullIn")%&gt;&gt; 
  &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                     &lt;td&gt;Comments &lt;/td&gt;
                     &lt;td&gt;&lt;input type="text" name="id" value=
  &lt;%=res.getString("comments")%&gt;&gt; &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                     &lt;td&gt;&lt;/td&gt;
                     &lt;td&gt;&lt;input type="submit" value="Update" name="update"&gt; &lt;/td&gt;
                  &lt;/tr&gt;
  
              &lt;%}%&gt;            
      &lt;/table&gt;
      &lt;/form&gt;
   &lt;/body&gt;
   &lt;/html&gt;
  </code></pre>
  
  <p>And my EditRecord servlet:</p>
  
  <pre><code>import java.io.IOException;
  import java.io.PrintWriter;
  import java.sql.Connection;
  import java.sql.ResultSet;
  import java.sql.Statement;
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  public class EditRecord extends HttpServlet {
  
      Connection conn;
      ResultSet res;
      Statement stmt;
      String id, query;
      DatabaseConnection dbconn;
  
  
      protected void processRequest(HttpServletRequest request, HttpServletResponse  
      response)
              throws ServletException, IOException {
          response.setContentType("text/html;charset=UTF-8");
          PrintWriter out = response.getWriter();
          try {
  
              id = request.getParameter("id");
              dbconn = new DatabaseConnection();
              conn = dbconn.setConnection();
              stmt = conn.createStatement();
              query = "select * from inventory where id = "+id;
              res = dbconn.getResult(query, conn);
  
  
          }catch(Exception e){
  
  
  
          }
          finally {
              request.setAttribute("EditData", res);
              RequestDispatcher rd = request.getRequestDispatcher("editdata.jsp");
              rd.forward(request, response);
              out.close();
          }
      }
  
  
      /**
       * Handles the HTTP &lt;code&gt;GET&lt;/code&gt; method.
       *
       * @param request servlet request
       * @param response servlet response
       * @throws ServletException if a servlet-specific error occurs
       * @throws IOException if an I/O error occurs
       */
      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          processRequest(request, response);
      }
  
      /**
       * Handles the HTTP &lt;code&gt;POST&lt;/code&gt; method.
       *
       * @param request servlet request
       * @param response servlet response
       * @throws ServletException if a servlet-specific error occurs
       * @throws IOException if an I/O error occurs
       */
      @Override
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          processRequest(request, response);
      }
  
      /**
       * Returns a short description of the servlet.
       *
       * @return a String containing servlet description
       */
      @Override
      public String getServletInfo() {
          return "Short description";
      }// &lt;/editor-fold&gt;
  
  }
  </code></pre>
  
  <p>Again, the long and short of my problem is that full strings of data are not returned after spaces.  So 'TOM JONES' only returns 'TOM' to the form above for editing.  How do I get the full string of data to be returned.  I don't know if it matters, but I used VARCHAR for all my record info.</p>
  
  <p>Thanks for any and all help.</p>