Private list<map<string, object>> List = new arraylist<map<string,object>> ();p ublic String Queryall () {Connection conn = null; Statement sta = null; ResultSet rs = null;try {class.forname ("Com.mysql.jdbc.Driver"); conn = Drivermanager.getconnection ("jdbc:mysql:// Localhost:3306/easyui "," root "," root "); sta = Conn.createstatement (); rs = Sta.executequery (" SELECT * from E_user "); ResultSetMetaData MD = Rs.getmetadata (); Get the result set structure information, meta data int columnCount = Md.getcolumncount (); Gets the number of columns while (Rs.next ()) {map<string,object> rowdata = new hashmap<string,object> (), for (int i = 1; I <= Co Lumncount; i++) {rowdata.put (Md.getcolumnname (i), rs.getobject (i));} List.add (RowData);}} catch (ClassNotFoundException e) {e.printstacktrace ();} catch (SQLException e) {e.printstacktrace ();} Return "Success";}
ResultSet Brief Introduction:
ResultSet includes all rows that conform to the conditions in the SQL statement, and it passes through a set of Get methods (these get methods can access different columns in the current row)
Provides access to the data in these rows.
The Resultset.next method is used to move to the next line in the ResultSet so that the next line becomes the current row.
The Rs.getobject (i) above is the data value for this row
ResultSetMetaData Brief Introduction:
The Resultsetmeta object can be obtained by using ResultSet's GetMetaData method, and ResultSetMetaData stores resultset metadata.
The so-called metadata in English is interpreted as "data about data", literal translation into Chinese is "the relevant information" or "descriptive data",
is actually the data describing and explaining the meaning. Taking the metadata of result as an example, resultset is present in tabular form, so GetMetaData
Includes information that must be available for tables such as the field name, type, and number of data. There are several methods in the ResultSetMetaData class.
ResultSetMetaData Rsmd=rs.getmetadata ();
1. Getcolumcount () method
Returns the number of all fields
2. Getcolumname () method
Gets the name of the field based on the index value of the field.
3. Getcolumtype () method
Get an exponential type field from a field
Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.
To change the JDBC ResultSet result set to list