Skip to content

Commit a2ee65a

Browse files
use linkedhashmap to preserve the order of columns while parsing recordset to list
1 parent cdb7e1e commit a2ee65a

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

src/main/java/com/powertester/database/DBConnection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import java.sql.SQLException;
1414
import java.sql.Statement;
1515
import java.util.ArrayList;
16-
import java.util.HashMap;
16+
import java.util.LinkedHashMap;
1717
import java.util.List;
1818
import java.util.Map;
1919
import lombok.extern.slf4j.Slf4j;
@@ -124,7 +124,7 @@ private static List<Map<String, String>> getResultListFromResultSet(ResultSet re
124124
ResultSetMetaData metaData = resultSet.getMetaData();
125125
int columnCount = metaData.getColumnCount();
126126
while (resultSet.next()) {
127-
Map<String, String> row = new HashMap<>();
127+
Map<String, String> row = new LinkedHashMap<>();
128128
for (int i = 1; i <= columnCount; i++) {
129129
row.put(metaData.getColumnName(i), resultSet.getString(i));
130130
}
@@ -148,7 +148,7 @@ public Map<String, String> runStoredProcedure(String sql, String... outputParame
148148
statement.execute();
149149

150150
// Get output parameters
151-
Map<String, String> resultMap = new HashMap<>();
151+
Map<String, String> resultMap = new LinkedHashMap<>();
152152
for (String outputParameter : outputParameters) {
153153
resultMap.put(outputParameter, statement.getString(outputParameter));
154154
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
GENDER,ID,LAST_NAME,FIRST_NAME,AGE
2-
Male,1,Doe,John,30
3-
Female,2,Smith,Jane,25
4-
Male,3,Brown,Alex,28
1+
ID,FIRST_NAME,LAST_NAME,AGE,GENDER
2+
1,John,Doe,30,Male
3+
2,Jane,Smith,25,Female
4+
3,Alex,Brown,28,Male

0 commit comments

Comments
 (0)