表结构如图
代码
@Autowired
JdbcTemplate jdbcTemplate;
@Test
public void getColumnNames() throws Exception {
String sql = "select * from tb_test where 1=2 ";
SqlRowSet sqlRowSet = jdbcTemplate.queryForRowSet(sql);
SqlRowSetMetaData sqlRsmd = sqlRowSet.getMetaData();
String[] columnNames = sqlRsmd.getColumnNames();
System.out.println(Arrays.toString(columnNames));
}
结果
[ID, NAME, CODE, CTIME]