Advertisement
Latinist

Untitled

Apr 10th, 2020
693
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. package com.antonromanov.springboothelloworld;
  2.  
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.jdbc.core.JdbcTemplate;
  5. import org.springframework.stereotype.Service;
  6. import javax.sql.DataSource;
  7.  
  8.  
  9. @Service
  10. public class DaoService {
  11.  
  12.     private final JdbcTemplate template;
  13.  
  14.     public int getCount() {
  15.         return template.queryForObject(
  16.                 "SELECT COUNT(*) FROM test_jdbc.public.user", Integer.class);
  17.     }
  18.  
  19.     @Autowired
  20.     public DaoService(DataSource dataSource) {
  21.         this.template = new JdbcTemplate(dataSource);
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement