title: How to execute few queries in one transaction in my DAO class? Is it possible to do it creating one query?
body: <p>I'm new in Java development and I need some help with writing batch of queries in my java DAO class.
  In my DAO class I would like to write an update query that will update few tables. Something like: </p>
  
  <pre><code>UPDATE deals, vehicles SET deals.client= "client",
  vehicles.vehicleIdNumber="123456"
  WHERE deals.id ="123" and deals.id= vehicles.id; 
  </code></pre>
  
  <p>This will work if I execute it in MySQL but if I want to do this in my DAO class I have to write two queries in batch. 
  The problem is that I don't know how to do it. From what I've already researched I can only find some examples using JDBC, Spring, Hibernate, but I don't use any of this in my application. </p>
  
  <p>When I do an update for a single table I have something like this:</p>
  
  <pre><code>public void updateDeal(String dealNumber, Integer dealType) {
          Query upQ = em.createQuery(
                          "update Deals d set d.dealType = :dealType  where d.dealNumber= :dealNumber")
                  .setParameter("dealType", dealType)
                  .setParameter("dealNumber", dealNumber);
          upQ.executeUpdate();
  </code></pre>
  
  <p>How can I update two or more tables in one transaction similar to the above, but without using JDBC, Spring, Hibernate...</p>
  
  <p>Tnx!</p>
  
  <p>UPDATE:
  I realized that I haven't explained it well what I meant with no using JDBC...my mistake.
  So I have JDBC, I have connection with my DB and it's working fine with a single table statements.
  I actually want to know if there is other way of doing this rather than something like:
  <a href="http://w3processing.com/index.php?subMenuId=146" rel="nofollow">http://w3processing.com/index.php?subMenuId=146</a>
  In this example you have to first get connection to the DB, than create statement and than add all the queries in the batch.
  When I'm creating a query for updating one table is pretty simple (it's exactly like I have shown in the code example above). 
  I want to know if there is some simpler way of doing this for updating more than one table. I don't want to create each time a connection to my DB.</p>
  
  <p>I've tried something like:</p>
  
  <pre><code>public void updateDeal(Integer id, String client,
              String vechicleNumber)
  Query query = em.createQuery("UPDATE Deals, Vehicles SET deal.client=:client, vehicle.vehicleNumber=:vechicleNumber WHERE deal.id =:id AND deal.id=vehicles.id ").
                setParameter("client", client).setParameter("id", dealID).
                setParameter("vechicleNumber ", vechicleNumber );
  </code></pre>
  
  <p>and I get this error:</p>
  
  <pre><code>According to the error in the console,  I have synatax error:
  Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: , near line 1, column 35 
  </code></pre>