playframework - Play framework return error: no suitable method found for ok(ArrayList<String[]>)] -
i want play framework send arraylist android application. can view list on android app. play framework cannot return arraylist) how can solve this? thank you.
public static result get_latestlist() throws classnotfoundexception, sqlexception { string latestlist = ""; arraylist<string[]> etlist = new arraylist<string[]>(); multipartformdata body = request().body().asmultipartformdata(); string pagenumber = body.asformurlencoded().get("pagenumber")[0]; connection conn = null; statement stmt = null; resultset rs = null; class.forname("com.mysql.jdbc.driver"); conn = drivermanager.getconnection("jdbc:mysql://localhost/iea_db", "rt", "yt"); stmt = conn.createstatement(); rs = stmt.executequery("select * list_table;"); while (rs.next()) { string[] oneset = new string[4]; oneset[0] = rs.getstring("username"); oneset[1] = rs.getstring("idname"); oneset[2] = rs.getstring("comment"); oneset[3] = rs.getstring("rank"); etlist.add(oneset); } conn.close(); return ok(etlist); }
i find solution: use json in play framework, this:
objectnode result = json.newobject(); result.put("draw", integer.valueof(params.get("draw")[0])); result.put("recordstotal", itotalrecords); result.put("recordsfilter", itotaldisplayrecords); return ok(result);
in android, this:
@override protected jsonobject doinbackground(string... _uri) { httpclient httpclient = new defaulthttpclient(); httpget httpget = new httpget(_uri[0]); try { httpresponse httpresponse = httpclient.execute(httpget); if (httpresponse.getstatusline().getstatuscode() == httpstatus.sc_ok) { bytearrayoutputstream outputstream = new bytearrayoutputstream(); httpresponse.getentity().writeto(outputstream); outputstream.close(); return new jsonobject(outputstream.tostring()); } else { httpresponse.getentity().getcontent().close(); throw new ioexception(); } } catch (ioexception e) { e.printstacktrace(); } catch (jsonexception e) { e.printstacktrace(); } return null; }
Comments
Post a Comment