写一段java代码,实现在srping cloud框架下从数据库data的p表中按照时间顺序降序排列的查询
时间: 2023-02-23 13:55:03 浏览: 81
基于springboot+springcloud实现的电商网站项目源代码+数据库,spring cloud进行微服务框架开发
public List<String> queryDataByTimeFromTableP(String dataSourceName) {
String sql = "SELECT * FROM P ORDER BY time DESC";
List<String> list = new ArrayList<>();
try {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSourceName);
list = jdbcTemplate.query(sql, new RowMapper<String>() {
@Override
public String mapRow(ResultSet rs, int rowNum) throws SQLException {
return rs.getString("data");
}
});
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
阅读全文