跳至主要内容

博文

目前显示的是标签为“Jdbc”的博文

Simplified Jdbc operations

Simplified Jdbc operations As I stated in the last post, Spring DaoSupport and Template API is not recommended in new projects. But for Jdbc API, how to simplify the data operations? Spring jdbc support(spring-jdbc maven dependency) provides some simplified APIs for Jdbc operations. Overview Unlike the approach of JdbcDaoSupport, it is no need to subclass the JdbcDaoSupport class. A SQL query(and modifying query) execution will be wrapped in a single object. All you need to do is creating a new class(by subclassing the related operation object) for every SQL query execution. In these operation classes, MappingSqlQuery , SqlUpdate , SimpleJdbcInsert are used frequently. Follow the following steps to use them. Compose sql query statement, and declare parameters used in the sql statement. Call compile() method from super class to prepare the sql statement. Call execute methods to execute the query. MappingSqlQuery MappingSqlQuery is designated for e...

Legacy DaoSupport And Template API

Legacy DaoSupport And Template API In the Spring core framework(provided in the spring-jdbc and spring-orm maven dependency), it has provided a series of standard DaoSupport APIs and Template pattern to help user to retrieve data from database and save data back into database. Jdbc support There is a JdbcDaoSupport class and JdbcTempalte class provided for Jdbc operations. Using these APIs in your project is very simple and stupid. Firstly register a DataSource bean, and also declare a Jdbc transaction manager(we will discuss Spring transaction in future posts). <jdbc:embedded-database id="dataSource" type="H2"> <jdbc:script location="classpath:/com/hantsylabs/example/spring/config/schema.sql" /> </jdbc:embedded-database> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="da...