简体   繁体   中英

Using POI, JAVA & MySQL to Compile an Excel Document

I am trying to gather information from a MySQL database and then exporting that information to a Excel document using POI and JAVA.

The only problem I am experiencing is increasing the number after data.put , each time if(rs.next()) is executed, for example:

Map<String, Object[]> data = new HashMap<>();
            data.put("1", new Object[] {"Emp No.", "Name", "Salary"});

            if(rs.next()) {
                data.put("2", new Object[] {1d, "John", 1500000d, "Test"});
            }

The 2 should increase to 3 then to 4 then to 5 , depending on the rows in the MySQL database.

Any help is appreciated.

int cnt=2;

while(rs.next()) 
{
    data.put(""+cnt, new Object[] {1d, "John", 1500000d, "Test"});
    cnt++;//increment to 3, 4, etc
}

try like this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM