title: How to insert values into database using queries using entity manager, persistence using a java class?
body: <p>I want to insert data into a table using the following code</p>
  
  <pre><code>    public User registerUser(String usr, String pwd) {
  
      u=em.find(User.class,usr);
      if(u!=null)
      {
          return null;
      }
      String query1 = "insert into users values('" + usr + "','" + pwd +"')";
      Query q = em.createQuery(query1);
      u=em.find(User.class,usr);
      return u;
  </code></pre>
  
  <p>}</p>
  
  <p>here <code>'u</code>' is the object of <code>User</code> class and <code>em</code> is <code>EntityManager</code>.</p>
  
  <p>I get this following exception: </p>
  
  <blockquote>
    <p>Servlet.service() for servlet action threw exception
    org.hibernate.hql.ast.QuerySyntaxException: expecting OPEN, found 'values' near line 1, column 19 [insert into users values('pawan','am')]</p>
  </blockquote>