Midlet displaying data from a servlet
| Thu, 2005-09-22 22:17 | |
|
Hi I am writing an application for a mobile. My midlet connects to a java servlet which has a database connection. So far information received from the database, is displayed as follows On the servlet: res.setContentType("text/plain"); PrintWriter out = res.getWriter(); ……….. ……….. rs = stmt.executeQuery("SELECT * FROM food"); while(rs.next()) { out.print(rs.getObject(1).toString()); out.print(rs.getObject(2).toString()); out.print(rs.getObject(3).toString()); } And in the midlet, the information is got by textFromServer = new String(servletData); append(textFromServer); The above snippets of code works and displays all the data from the database. Problem is it just displays one long string. How do I separate the “servletData” out so that I can add a choice group to each row? Do I need to use xml to help me in design? I don’t know how to use xml or where to start with it. Any pointers? Thank you |
|






Forum posts: 14
I guess first of all u use a seperator like \n between the rows when u send the data back to the
mobile and then in the midlet, use this seperator to segregate every single row and collect
these in a String[].
After that u can add these strings into the choicegroup.
I hope this should solve ur problem.
Cheers,
Amulya
ARB
Forum posts: 6
I was trying to do as you said using split()
// Getting string from server
User_Name = new String(servletData);
//each word is divided by a *
//store each word in an array
String[] starwords = User_Name.split("\\*");
for (int i=0; i<starwords.length; i++)
 {append(starwords[i]);}
This worked great until I added the code to my midlet.
spilt() is not recognised by midp.
Any other ideas of how I could break up the string from the servlet?
Thank you
Forum posts: 14
u r right. split() function is not supported by midp.
but still i think we can fashion something.
use
indexOf(String ) to find the first instance of the seperator, and use the subString method to get the string uptill that.
next use
indexOf(String , int fromindex) to find further instances of the seperator, and use the subString
method to get the required strings.
the above methods have to be kept in the loop.
I think this should work since all the above methods are supported by midp.
Tell me if even this doesn't work.
Cheers,
Amulya
ARB