- 直接执行sql语句
@Autowired
private TDataSource dataSource;
//或者
@Autowired
private DataSource dataSource;
String[] split = StringUtils.split(jobArguments, "@@@");
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
for (int i = 0; i < split.length; i++) {
jdbcTemplate.execute(split[i]);
}
- 带有返回结果的sql语句执行
private static String SQL = "select* from where id = ?";
private static Long ID
List<Map<String, Object>> list = jdbcTemplate.queryForList(SQL, new Object[] { ID });
list.stream().forEach(map -> {
Id = ((BigInteger) map.get("id")).toString();
Long Id = ((BigInteger) map.get("id")).longValue();
}