Thursday, 15 May 2014

java - How to add all row elements in database to JSON object -



java - How to add all row elements in database to JSON object -

i'm trying retrieve elements in database , display in webpage.but code able retrieve 1 row element. problem is, retrieves element adds lastly row element object. think elements retrieved first overwritten because of displays lastly row element. can tell me how add together row elements json object. please help me.

code :

while(rs.next()){ imagefile.setname(rs.getstring("imagename").trim()); imagefile.setdisc(rs.getstring("imagedisc").trim()); imagefile.setimageid(rs.getint("imageid")); imagefile.setalbumid(rs.getint("albumid")); byte imagedata[] = rs.getbytes("imagethumb"); string encoded = datatypeconverter.printbase64binary(imagedata); imagefile.setthumb(encoded); byte image1data[] = rs.getbytes("imagethumb"); string encoded1 = datatypeconverter.printbase64binary(image1data); imagefile.setfull(encoded1); }

the finish source code in this question

please help me........thanks....

use list collection maintain row-values of db, - list<imagefileinfo> denotes list containing of imagefileinfo objects . , serialize list json string.

list<imagefileinfo> imagefilelist = new arraylist<imagefileinfo>(); while(rs.next()){ imagefileinfo info = new imagefileinfo(); info..setname(rs.getstring("imagename").trim()); ... imagefilelist.add(info); }

json serialization -

type typeoflist= new typetoken<list<imagefileinfo>>(){}.gettype(); string s = gson.tojson(imagefilelist , typeoflist);

java json java-ee object

No comments:

Post a Comment