0
public List<Map<String, Object>> getReport()
{
    Connection connection = createConnection();
    List<Map<String, Object>> sqlReport = new ArrayList<>();
    if (connection == null)
    {
        return sqlReport;
    }

    try
    {

        sqlReport = new QueryRunner().query(connection, "SELECT * FROM TABLE", new MapListHandler());

    } catch (SQLException ex)
    {
        Logger.getLogger(SQLManager.class.getName()).log(Level.SEVERE, null, ex);

    } finally
    {

        try
        {
            DbUtils.close(connection);

        } catch (SQLException ex)
        {
            Logger.getLogger(SQLManager.class.getName()).log(Level.SEVERE, null, ex);

        }

    }
    return sqlReport;
}

This code will return an Array of HashMaps. The issue is, I want to save this to CSV (using Apache Commons CSV), but the key values in a Hashmap are not ensured to retain order. How do I retain ordering of the columns? I know using a LinkedHashMap will do it... but I don't think dbutils will convert it to this.

trilogy
  • 1,738
  • 15
  • 31

0 Answers0