Integration JDBC
1, the basic operation
1.1 Creating project
1.2 the configuration parameters (the application.properties)
spring.datasource.username=root spring.datasource.password=123456 spring.datasource.url=jdbc:mysql://localhost:3306/javas1?serverTimezone=UTC spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
1.3 Test
@Autowired DataSource dataSource; @Test public void test1() throws SQLException { System.out.println(dataSource.getClass()); System.out.println(dataSource.getConnection()); }
2, operation of the database (use the JdbcTemplate)
@Autowired JdbcTemplate jdbcTemplate; @Test public void test2(){ List<User> query = jdbcTemplate.query("select * from t_user", BeanPropertyRowMapper.newInstance(User.class)); System.out.println(query); }