am new to this java world.. i just wanted to know how to convert a db populated list to json and then call this json in javascript?
i saw many examples inputting data manually into list, but i dnt understand how to convert this list.. should i create another method or something else?
Thanks for your patience and reply.
For example, i have a list of type members
public List<Member> getMember() throws SQLException
{
//connection
List<Member> listmember = new ArrayList<Member>();
ps = con.prepareStatement(myquery);
rs = ps.executeQuery();
while(rs.next())
{
Member fsta = new Member();
fsta.setName(rs.getString(2));
fsta.setJan(rs.getString(6));
fsta.setFeb(rs.getString(7));
fsta.setMar(rs.getString(8));
listmember .add(fsta);
}// end of while
return listmember ;
}
Now i want to convert the listmember to json, in return call the json in my javascript.
Hope this makes it clear now
you can create list to json array as follow:
refer Simple List to Json example
then to send it to your wepage. in your webpage you can pass it through javascript.