java - How to get the MySQL query results into a ArrayList<object> -
i have sql query results in multiple columns. want execute query , results arraylist<>
instead of resultset
. class column definitions
public class record{ private string filename; private string fileid; private string loan; private string page; }
query :
string query = "select filename, fileid, loannumnber, pagenumber table"; resultset rs = stmt.executequery(query);
i want results of query in recorddata object.
arraylist<record> recorddata = new arraylist<record>;
please suggest how arraylist can populated directly correct mapping.
use following code snippet if want implement yourself. convert result set record
objects , add arraylist
.
record record; while(rs.next()){ record = new record(); string filename = rs.getstring("filename"); string fileid = rs.getstring("fileid"); string loannumnber = rs.getstring("loannumnber"); string pagenumber = rs.getstring("pagenumber"); record.setfilename(filename); record.setfileid(fileid); record.setloan(loannumnber); record.setpage(pagenumber); recorddata.add(record) } rs.close();
otherwise, if want use third party frameworks there lot of options such hibernate, ibatis etc.
Comments
Post a Comment