title: How to enable sql queries console logging in spring JDBC
body: <p>I am new to prepared statement and i'm trying to use basic insert and update using jdbcTemplate which is also working fine but i want logs to be printed for sql queries in consle and i'm not sure how to achieve that. I have added required properties in application.properties file but it's not working. Kindly help me out by giving some appropriate suggestions or refernece link which may solve my problem. Thanks in advance...</p>
  
  <p>SampleConfiguration.java</p>
  
  <pre><code>@Configuration
  public class SampleConfiguration 
  {
      @Bean
      public DataSource mysqlDataSource() 
      {
          DriverManagerDataSource dataSource = new DriverManagerDataSource();
          dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
          dataSource.setUrl("jdbc:hsqldb:hsql://localhost/");
          dataSource.setUsername("SA");
          dataSource.setPassword(""); 
          return dataSource;
      }
  
      @Bean
      public JdbcTemplate jdbcTemplate(DataSource dataSource)
      {
          JdbcTemplate jdbcTemplate = new JdbcTemplate();
          jdbcTemplate.setDataSource(dataSource);
          return jdbcTemplate;
      }
  
  }
  
  </code></pre>
  
  <p>SampleService.java</p>
  
  <pre><code>@Service
  public interface SampleService 
  {
      public int insert();
      public long getCount();
  }
  </code></pre>
  
  <p>SampleServiceImpl.java</p>
  
  <pre><code>@Service
  public class SampleServiceImpl implements SampleService 
  {
  
      @Autowired
      JdbcTemplate jdbcTemplate;
  
      @Override
      public int insert()
      {
          return jdbcTemplate.update("insert into batch values(?,?)","field1","field2");
      }
  
      @Override
      public long getCount()
      {
          return jdbcTemplate.queryForObject("select count(*) from batch", Long.class);
      }
  
  }
  
  </code></pre>
  
  <p>SpringjdbcApplication.java</p>
  
  <pre><code>@SpringBootApplication
  public class SpringjdbcApplication 
  {
      public static void main(String[] args) 
      {
          ApplicationContext context  = SpringApplication.run(SpringjdbcApplication.class, args);
          SampleService service = context.getBean(SampleService.class);
          System.err.println("The number of rows inserted = "+service.insert());
          System.err.println("The count of batch class is = "+service.getCount());
      }
  
  }
  </code></pre>
  
  <p>Entity.java</p>
  
  <pre><code>@Entity
  public class Batch implements Serializable 
  {
  
      private static final long serialVersionUID = -5687736664713755991L;
  
      @Id
      @Column(name="field1")
      private String field1;
  
      @Column(name="field2")
      private String field2;
  
          ... getter, setter and no-arg constructor
  }
  </code></pre>
  
  <p>application.properties</p>
  
  <pre><code>spring.jpa.show-sql=true
  spring.jpa.hibernate.ddl-auto=none
  spring.jpa.properties.hibernate.format_sql=true
  
  logging.level.org.hibernate.SQL=debug
  logging.level.org.hibernate.type.descriptor.sql=trace
  </code></pre>
  
  <p>pom.xml</p>
  
  <pre><code>           &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-jdbc&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hsqldb&lt;/groupId&gt;
              &lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  </code></pre>
  
  <p>I want to know how to turn on sql statement logging on console and how to set other properties like auto commit off or on ???</p>