获取ResultSet集合查询出的字段名称

/**
 * 获取ResultSet集合查询出的字段名称
 * @return
 */
public List<String> getColumnName(){
	Connection conn = null;
	PreparedStatement ps = null;
	ResultSet rs = null;
	List<String> cols = new ArrayList<String>();
	try {
		conn = DBHelper.getConn();
		ps = conn.prepareStatement("select * from tableName");
		rs = ps.executeQuery();
		ResultSetMetaData rsmd = rs.getMetaData();
		for (int i = 1; i < rsmd.getColumnCount() + 1; i++) {
			String columnName = rsmd.getColumnName(i).toLowerCase();
			cols.add(columnName);
		}
	} catch (Exception e) {
		throw new WAFException(e);
	} finally {
		DBHelper.close(conn, ps, rs);
	}
	return cols;
}

猜你喜欢

转载自songlitao.iteye.com/blog/2258040