title: how to deal jquery ajax with jsp for database update?
body: <p>I have used ajax with jquery and my ajax url is calling another jsp page which submits form data to database the problem is whenever I'm running the insert query, its replying "Null values can't be inserted to database" kinda exception, but whenever I'm reloading same page and clicking submit button, its getting submitted to database.
  I think the problem is with something like postback method,
  I'm new to ajax so please need your help...</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      $(document).ready(function() {
          $('#save').click(function ()
          {
              $.ajax({
                  type: "post",
                  url: "test.jsp", //this is my servlet
                  data: "input=" +$('#id').val()+"&amp;output="+$('#op').val(),
                  success: function(msg){      
                          $('#output').append(msg);
                  }
              });
          });
  
      });
  &lt;/script&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;
      input:&lt;input id="id" type="text" name="" value="" /&gt;&lt;br&gt;&lt;/br&gt;
      output:&lt;input id="op" type="text" name="" value="" /&gt;&lt;br&gt;&lt;/br&gt;
      &lt;input type="button" value="save" name="save" id="save"/&gt;
     &lt;div id="output"&gt;&lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>JSP:</p>
  
  <pre><code>&lt;%@page import ="com.connectionUtil.ConnectionUtil"%&gt; 
  &lt;!DOCTYPE html&gt; 
  &lt;script src="js/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt; 
  &lt;% String id = request.getParameter("input");
      try {
          Connection con = ConnectionUtil.getConnection();
          String sql = "insert into test(ID,...) values ('" + id + "',...)";
          PreparedStatement ps = con.prepareStatement(sql);
          ps.executeUpdate();
      } catch (SQLException sqe) {
          out.println(sqe);
      }%&gt; 
  &lt;body&gt; &lt;h4&gt;&lt;%=id%&gt; is stored &lt;/h4&gt; &lt;/body&gt; &lt;/html&gt;
  </code></pre>