Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to apply JDBC in Spring Framework

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

How to carry out the JDBC application in Spring framework, I believe that many inexperienced people do not know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

First, look at the jdbctemplate configuration.

Needless to say, this dataSource uses the same data source as Hibernate.

DAO layer writing method

Service layer writing method

Spring configuration is that simple.

Of course, in DAO layer programs, we usually use an object wrapper.

Import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.support.JdbcDaoSupport; import com.fruitking.dao.jdbcdao.IAccessAnalyserDao; import com.fruitking.entity.AccessAnalyser; public class AccessAnalyserDaoImpl extends JdbcDaoSupport implements IAccessAnalyserDao {public List countGroupByYear () {String sql = "select to_char (t.createddate, 'yyyy') as cyear, count (*) as yearcount from accessanalyser t group by to_char (t.createddate,' yyyy')" List accessAnalyserList = this.getJdbcTemplate (). Query (sql, new AccessAnalyserRowMapper ()); return accessAnalyserList;} class AccessAnalyserRowMapper implements RowMapper {public Object mapRow (ResultSet rs, int rowNum) throws SQLException {AccessAnalyser accessAnalyser = new AccessAnalyser (); accessAnalyser.setYearName (rs.getString ("cyear")); accessAnalyser.setClickTimes (rs.getLong ("yearcount")); return accessAnalyser;}

In this way, you can use JDBC in the Spring framework like Hibernate, but you can use JDBC things at will.

After reading the above, have you mastered how to apply JDBC in the Spring framework? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report