1 Public StaticarraylistthrowsException {2PreparedStatement statement =NULL;3ResultSet SS =NULL;4String str = "";//Play log Use5ArraylistNewArraylist();6statement =conn.preparestatement (SQL);7 if(paras!=NULL&¶s.length!=0){8 for(inti = 0; i < paras.length; i++) {9 if(Paras[i].getclass (). Getsimplename (). Equals ("Integer")) {TenStatement.setint (i + 1), (Integer) paras[i]); Onestr+=Paras[i]; A}Else { -Statement.setstring (i + 1), (String) paras[i]); -str+=Paras[i]; the } - } - } -SS =statement.executequery (); +ResultSetMetaData RSMD = Ss.getmetadata ();//get column information for a result set - intColumnnum =Rsmd.getcolumncount (); + while(Ss.next ()) { AHashmap<string,object> Tmpmap =NewHashmap<string, object>(); at for(inti = 1; I <=columnNum; i++) {//Cyclic column assembly list - Tmpmap.put (Rsmd.getcatalogname (i), ss.getobject (i)); - } - Resultlist.add (tmpmap); - } - //logger.info ("sql:" +sql+ "paras:" +str+ "Resultlist:" +resultlist.size ()); in returnresultlist; -}
The above code function is not complete, as appropriate reference;
Parameter resolution:
Connection conn, database link java.sql.Connection;
String SQL, which needs to be performed to find the SQL java.lang.String;
Object[] Paras, which can support integer and string arguments, depending on the parameters to be passed in for the lookup, type Object
Arraylist
Statement Explanation:
ResultSetMetaData RSMD = Ss.getmetadata (); You can get the column information for the results of the SQL query
int columnnum = Rsmd.getcolumncount (); Get the number of columns in the result set
Rsmd.getcatalogname (i) to obtain the name of the column in the order of the data
Ss.getobject (i) Getting the data for the current column from the result set
Full JDBC Query result set encoding