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

/**
 * 获取ResultSet集合查询出的字段名称
 * @return
 */
public List getColumnName(){
	Connection conn = null;
	PreparedStatement ps = null;
	ResultSet rs = null;
	List cols = new ArrayList();
	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;
}

 

你可能感兴趣的:(java)