title: argument type mismatch in netbeans project while inserting to database
body: <p>i am creating a web page that allow admin to manage the menu item. for the delete part, it is success.. but there's error when i wish to insert a new menu.</p>
  
  <p>i am using phpmyadmin as my database</p>
  
  <p>i gt this error when i run my netbeans project</p>
  
  <p>HTTP Status 500-</p>
  
  <p><strong>type:</strong> Exception report</p>
  
  <p><strong>description:</strong> The server encountered an internal error () that prevented it from fulfilling this request.</p>
  
  <p><strong>exception:</strong> org.apache.jasper.JasperException: java.lang.IllegalArgumentException: argument type mismatch</p>
  
  <p><strong>root cause:</strong> java.lang.IllegalArgumentException: argument type mismatch</p>
  
  <p><strong>full stack trace</strong></p>
  
  <pre><code>java.lang.IllegalArgumentException: argument type mismatch
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:601)
  at org.apache.jasper.runtime.JspRuntimeLibrary.handleSetProperty(JspRuntimeLibrary.java:672)
  at org.apache.jsp.confirmadd_jsp._jspService(confirmadd_jsp.java:90)
  at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
  at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
  at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
  at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
  at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
  at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
  at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
  at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
  at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
  at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
  at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
  at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
  at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
  at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
  at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
  at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
  at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
  at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
  at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
  at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
  at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
  at java.lang.Thread.run(Thread.java:722)
  </code></pre>
  
  <p><em><strong>managemenu.jsp</em></strong></p>
  
  <pre><code>&lt;h3&gt;Add new menu&lt;/h3&gt;
  &lt;div&gt;
  &lt;form method="post" action="confirmadd.jsp"&gt;
  &lt;table&gt;
  &lt;tr&gt;&lt;td&gt;Food ID&lt;/td&gt;&lt;td&gt;:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="food_id" placeholder="food ID"/&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;Food Name&lt;/td&gt;&lt;td&gt;:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="food_name" placeholder="food name"/&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;Food Description&lt;/td&gt;&lt;td&gt;:&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="food_description" placeholder="food desc"/&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;Food Price&lt;/td&gt;&lt;td&gt;: &lt;/td&gt;&lt;td&gt;&lt;input type="text" name="food_price" placeholder="food price"/&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  &lt;input type="submit" value="Submit"/&gt;&lt;input type="reset" value="Reset"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><em><strong>confirmadd.jsp</em></strong></p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;%@ page import="java.util.*" %&gt;
  &lt;jsp:useBean id="newmenu" class="restaurantBean.menu" scope="session"/&gt;
  
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
      &lt;link href="css/jquery-ui-1.9.2.custom.css" rel="stylesheet"&gt;
      &lt;script src="js/jquery-1.8.3.js"&gt;&lt;/script&gt;
      &lt;script src="js/jquery-ui-1.9.2.custom.js"&gt;&lt;/script&gt;
      &lt;link href="css/style.css" rel="stylesheet" type="text/css"/&gt;
      &lt;title&gt;Confirm Add Food&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;center&gt;&lt;br&gt;&lt;h1&gt;Restaurant E-menu and Reservation System&lt;/h1&gt;&lt;br&gt;&lt;br&gt;
  
   &lt;a href="main.jsp"&gt;Home&lt;/a&gt;
      &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href="managemenu.jsp"&gt;Manage Menu&lt;/a&gt;
      &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href="updatestock.jsp"&gt;Update stock&lt;/a&gt;
  
  &lt;div class="content"&gt;
      &lt;h1&gt;Confirm Food&lt;/h1&gt;
      &lt;jsp:setProperty name="newmenu" property="food_id" value='&lt;%=request.getParameter("food_id")%&gt;'/&gt;
      &lt;jsp:setProperty name="newmenu" property="food_name" value="&lt;%=request.getParameter("food_name")%&gt;"/&gt;
      &lt;jsp:setProperty name="newmenu" property="food_description" value='&lt;%=request.getParameter("food_description")%&gt;'/&gt;
      &lt;jsp:setProperty name="newmenu" property="food_price" value='&lt;%=request.getParameter("food_price")%&gt;'/&gt;
  
      &lt;table id="form"&gt;
          &lt;tr&gt;&lt;th colspan="3"&gt;Food Details&lt;/th&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Food ID&lt;/td&gt;&lt;td&gt;:&lt;/td&gt;&lt;td&gt;&lt;jsp:getProperty name="newmenu" property="food_id"/&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Food Name&lt;/td&gt;&lt;td&gt;:&lt;/td&gt;&lt;td&gt;&lt;jsp:getProperty name="newmenu" property="food_name"/&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Food Description&lt;/td&gt;&lt;td&gt;:&lt;/td&gt;&lt;td&gt;&lt;jsp:getProperty name="newmenu" property="food_description"/&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Food Price&lt;/td&gt;&lt;td&gt;:&lt;/td&gt;&lt;td&gt;RM&lt;jsp:getProperty name="newmenu" property="food_price"/&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td colspan="3"&gt;&lt;input type="button" value="proceed" onclick="location.href='./addmenu'"/&gt;
      &lt;input type="button" value="Back" onClick="history.go(-1);return true;"&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;/table&gt;
  
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;jsp:include page="/WEB-INF/includes/footer.jsp" /&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><em><strong>menu.java</em></strong></p>
  
  <pre><code>package restaurantBean;
  
  public class menu {
  private String food_description;
  private String food_id;
  private String food_name;
  private double food_price;
  
  
  public void setFood_description(String a){
      food_description=a;
  }
  public String getFood_description(){
      return food_description;
  }
  public void setFood_id(String b){
      food_id=b;
  }
  public String getFood_id(){
      return food_id;
  }
   public void setFood_price(double c){
      food_price=c;
  }
  public double getFood_price(){
      return food_price;
  }
   public void setFood_name(String d){
      food_name=d;
  }
  public String getFood_name(){
      return food_name;
  }
  
  }
  </code></pre>
  
  <p><em><strong>addmenu.java</em></strong></p>
  
  <pre><code>package restaurantPackages;
  
  import restaurantBean.*;
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.sql.*;
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  
  @WebServlet(name = "addmenu", urlPatterns = {"/addmenu"})
  public class addmenu extends HttpServlet {
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      response.setContentType("text/html;charset=UTF-8");
      PrintWriter out = response.getWriter();
      try {
             Class.forName("com.mysql.jdbc.Driver");
  
             HttpSession session=request.getSession();
          menu m=(menu) session.getAttribute("newmenu");
  
  
          String url="jdbc:mysql://localhost:3306/restaurant";
          String username="root";
          String password="";
          Connection con=DriverManager.getConnection(url,username,password);
  
          Statement statement=con.createStatement();            
          //ResultSet result=statement.executeQuery("select food_id from food where food_name='"+m.getFood_name().trim()+"'");
          //int c = 0;
          //while(result.next()){
          //c=result.getInt(1);
          //}
          PreparedStatement stmt=con.prepareStatement("insert into food (food_id, food_name, food_description, food_price) values (?,?,?,?)");
          stmt.setString(1,m.getFood_id());
          stmt.setString(2,m.getFood_name());
          stmt.setString(3,m.getFood_description());
          stmt.setDouble(4,m.getFood_price());
  
          stmt.executeUpdate();
  
  
          stmt.close();
          con.close();
          menu food=new menu();
          session.setAttribute("food",food);
          RequestDispatcher dis=request.getRequestDispatcher("/WEB-INF/addsuccess.jsp");
          dis.forward(request,response);
      }
      catch(java.lang.ClassNotFoundException e){
            out.println("ClassNotFoundException:"+e.getMessage());
         }catch(SQLException e){
              out.println("SQLState:  " + e.getSQLState());
              out.println("Message:  " + e.getMessage());
              out.println("Vendor:  " + e.getErrorCode());
         }
      finally {            
          out.close();
      }
  }
  </code></pre>
  
  <p><em><strong>addsuccess.jsp</em></strong></p>
  
  <pre><code>&lt;div class="content"&gt;
  
  &lt;tr&gt;&lt;td&gt;Successfully add food ID = ${food.food_id} from restaurant&lt;/td&gt;&lt;/tr&gt;
  &lt;table id="form"&gt;
          &lt;tr&gt;&lt;th colspan="3"&gt;New Added Food Details&lt;/th&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Food ID&lt;/td&gt;&lt;td&gt;:&lt;/td&gt;&lt;td&gt;${food.food_id}&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Food Name&lt;/td&gt;&lt;td&gt;:&lt;/td&gt;&lt;td&gt;${food.food_name}&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Food Description&lt;/td&gt;&lt;td&gt;:&lt;/td&gt;&lt;td&gt;${food.food_description}&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;Food Price&lt;/td&gt;&lt;td&gt;:&lt;/td&gt;&lt;td&gt;${food.food_price}&lt;/td&gt;&lt;/tr&gt;
  
      &lt;/table&gt;
  &lt;tr&gt;&lt;td&gt;&lt;input type="button" value="Continue Manage Menu" onclick="location.href='managemenu.jsp'"/&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;input type="button" value="View Menu" onclick="location.href='main.jsp'"/&gt;    &lt;/td&gt;&lt;/tr&gt;
  </code></pre>