View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.test.integration.transaction.extras;
8   
9   import java.sql.Types;
10  
11  import org.springframework.jdbc.core.JdbcTemplate;
12  
13  public class JdbcLibraryDao implements LibraryDao
14  {
15  
16      private JdbcTemplate jdbcTemplate;
17  
18      public void setJdbcTemplate(JdbcTemplate jdbcTemplate)
19      {
20          this.jdbcTemplate = jdbcTemplate;
21      }
22  
23      public boolean insertBook(Book book) throws Exception
24      {
25          String sql = "insert into book (id, title, author) values (?,?,?)";
26          Object args[] = new Object[] {new Integer(book.getSerialNo()), book.getTitle(), book.getAuthor()};
27          int types[] = new int[] {Types.INTEGER, Types.VARCHAR, Types.VARCHAR};
28          try
29          {
30              jdbcTemplate.update(sql, args, types);
31              return true;
32          }
33          catch (Exception e)
34          {
35              System.out.println(e.getMessage());
36              throw e;
37              //return false;
38          }
39      }
40  }