JDBC Template Concept
To simplify persistence, spring provides the JDBC template component on top of the JDBC API
Provide a unified template:
Environment configuration
1. Create MySQL Database
2. Build MAVEN projects and introduce dependencies
3. Configure Spring configuration file
Database Connection Configuration
JDBC Connection Configuration
Basic operations
Execute
Typically executes DDL statements
Update or BatchUpdate
Int update (String sql,object[] args)
Int update (String sql,object ... args)
Int[] BatchUpdate (String [] sql)
Int[] BatchUpdate (String [] sql,list<object[]> args)------------performing isomorphic sql
Query or queryxxx querying simple objects
Query A
T queryforobject (String sql,class<t> type)
T queryForObject (String sql,object[] args,class<t> type)
T queryForObject (String sql,class<t> type,object ... args)
Querying multiple
List<t> queryforlist (String sql,class<t> type)
List<t> queryForList (String sql,object[] args,class<t> type)
List<t> queryforlist (String sql,class<t> type,object ... args)
Querying Complex objects
Query A
Map queryforobject (String sql)
Map queryForObject (String sql,object[] args)
Map queryforobject (String sql,object ... args)
Querying multiple
list< map<string,object>> queryforlist (String sql)
list< map<string,object>> queryForList (String sql,object[] args)
list< map<string,object>> queryforlist (String sql,object ... args)
Querying complex objects (encapsulated into entities)
Query A
T queryForMap (String sql,rowmapper<t> Mapper)
T queryForMap (String sql,object[] args, rowmapper<t> mapper)
T queryForMap (String sql, rowmapper<t> mapper,object ... args)
Querying multiple
List<t> queryforlist (String sql, rowmapper<t> Mapper)
List<t> queryForList (String sql,object[] args, rowmapper<t> mapper)
List<t> queryforlist (String sql, rowmapper<t> mapper,object ... args)
Callnamedparameterjdbctemplate
Case process:
After setting up the development environment
1. Creating a DAO interface
2. Create an interface implementation class
Manage with XML:
Annotation Injection
Advantages and Disadvantages
Excellent: simple, flexible
Missing: SQL and Java code Doping, feature is not rich
Persistent operation features: must, mechanical
ORM: Object-Relationship (JDBC template is not ORM)
The JDBC template:spring framework encapsulates JDBC operations in a simple, flexible but not powerful
Spring-jdbc Template