Use ResultSet to write a common query method.
This method is very bad and will be optimized later
/*** Common query method: SELECT */@ SuppressWarnings ({"unchecked", "rawtypes"}) public List testResultSet (String SQL) {Connection connection = null; statement statement = null; ResultSet rs = null; try {// 1. obtain Connection connection = JDBCTools. getConnection (); // 2. get Statement statement = connection. createStatement (); // 4. run the query to obtain ResultSet rs = statement.exe cuteQuery (SQL); // 5. process ResultSet List list = new ArrayList (); ResultSetMetaData metaData = rs. getMetaData (); int columnCount = metaData. getColumnCount (); while (rs. next () {Map rowData = new HashMap (); for (int I = 1; I <columnCount; I ++) {rowData. put (metaData. getColumnName (I), rs. getObject (I);} list. add (rowData) ;}for (int I = 0; I <list. size (); I ++) {System. out. print (list. get (I); System. out. println ();} return list;} catch (Exception e) {e. printStackTrace (); return null;} finally {// 6. disable the corresponding resources of the database, JDBCTools. release (rs, statement, connection );}}
I printed the result to the console to make it easier to see the result. Actually, this is not allowed.
Too lazy to write Test Methods