Full JDBC Query result set encoding

Source: Internet
Author: User

1  Public StaticarraylistthrowsException {2PreparedStatement statement =NULL;3ResultSet SS =NULL;4String str = "";//Play log Use5ArraylistNewArraylist();6statement =conn.preparestatement (SQL);7         if(paras!=NULL&&paras.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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.