使用jdbc模板在api中关闭连接

时间:2019-05-22 07:39:22

标签: spring-boot

我必须在春季制作REST API,但想在API结束后关闭连接。怎么做,因为连接没有在数据库端关闭

@Repository
public class ThingworxDaoImp implements ThingworxDao{
    @Autowired
    private JdbcTemplate jdbcTemplate;      
    @Override
    public List<ThingworxModel> getAllList(){
        System.out.println("ThingworxDaoImp is runing");

        String Query1 ="Query.query1"

        System.out.println("MRIDUL:"+Query1);

        List<ThingworxModel> thingworxModelList = jdbcTemplate.query(Query1, new RowMapper<ThingworxModel>() {
        @Override
        public ThingworxModel mapRow(ResultSet rs , int rowNum) throws SQLException{
            ThingworxModel mThingworxModel = new ThingworxModel();
            mThingworxModel.setTotal_thing(rs.getInt("total_thing"));
            mThingworxModel.setTemplate_name(rs.getString("template_name"));
            mThingworxModel.setConnected_things(rs.getInt("connected_things"));
            mThingworxModel.setDisConnected(rs.getInt("DisConnected"));

            return mThingworxModel;

        }

    });

return thingworxModelList;

        }

0 个答案:

没有答案