1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| package cn.idea360.assistant.dev.jdbc;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DriverManagerDataSource;
import java.util.List;
public class SimpleJdbcTemplate {
public static void main(String[] args) { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://localhost:3306/employees?serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true"); dataSource.setUsername("root"); dataSource.setPassword("root");
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); List<String> list = jdbcTemplate.queryForList("SHOW TABLES;", String.class); System.out.println(list); } }
|