sudo docker images mysql latest 18f13d72f7f0 2 weeks ago 383.4 MB
### application.yaml ### mysql config spring: datasource: dbcp: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://192.168.18.129:3306/test1 username: root password: 123456
@Bean
@ConfigurationProperties(prefix = "spring.datasource.dbcp")
public DataSource mysqlSource() {
return DataSourceBuilder.create().build();
}
@Bean
public JdbcTemplate mysqlJdbcTemplate() {
return new JdbcTemplate(mysqlSource());
}
JdbcTemplate jdbcTemplate = mysqlJdbcTemplate();
jdbcTemplate.execute("DROP TABLE IF EXISTS customers");
jdbcTemplate.execute("CREATE TABLE customers(" + "id SERIAL, first_name VARCHAR(255), last_name VARCHAR(255))");
// Split up the array of whole names into an array of first/last names
List<Object[]> splitUpNames = Arrays.asList("John Woo", "Jeff Dean", "Josh Bloch", "Josh Long")
.stream() .map(name -> name.split(" ")) .collect(Collectors.toList());
// Use a Java 8 stream to print out each tuple of the list
splitUpNames.forEach(name -> log.info(String.format("Inserting customer record for %s %s", name[0], name[1])));
// Uses JdbcTemplate's batchUpdate operation to bulk load data
jdbcTemplate.batchUpdate("INSERT INTO customers(first_name, last_name) VALUES (?,?)", splitUpNames);
log.info("Querying for customer records where first_name = 'Josh':");
jdbcTemplate.query(
"SELECT id, first_name, last_name FROM customers WHERE first_name = ?",
new Object[]{"Josh"}, (rs, rowNum) -> new Customer(rs.getLong("id"), rs.getString("first_name"), rs.getString("last_name")))
.forEach(customer -> log.info(customer.toString()));
mysql> select * from customers; +----+------------+-----------+ | id | first_name | last_name | +----+------------+-----------+ | 1 | John | Woo | | 2 | Jeff | Dean | | 3 | Josh | Bloch | | 4 | Josh | Long | +----+------------+-----------+ 4 rows in set (0.00 sec)
<properties> <java.version>1.8</java.version> </properties>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有