See a lot of people ask how to save the results from a query in a database as list<map>
I have studied it today, and if there is something wrong, please correct me.
ResultSet how to get in this is no longer elaborated on the Internet a bunch of search.
When we obtain resultset RS, we can convert to ResultSetMetaData objects.
ResultSetMetaData can be used to get an object about the type and property information of a column in a ResultSet object.
Look at the example below
Get ResultSetMetaData Object
ResultSetMetaData Rsmd=rs.getmetadata ();
Gets the number of columns returned in this ResultSet object
int count = Rsmd.getcolumncount ();
while (Rs.next ()) {
Map map=new HashMap ();
for (int i=1;i<count;i++) {
Gets the table directory name of the specified column
String Label=rsmd.getcolumnlabel (i);
Gets the value of the specified column in the current row of this ResultSet object as object in the Java programming language
Object object= Rs.getobject (i);
Match the field names and values in the database to a key value pair in a Map object
Map.put (Label.tolowercase (), object);
}
Put the map object encapsulated in each object into the list
List.add (map);
}
This allows any resultet to generate a list object in this way without considering how to correspond to the fields in the database.