Assuming you're talking about a CDC device, then the java.net.URLConnection is available, so you can use straight HTTP.
If you're asking about CLDC, then you'll need to fudge something with the classes in the javax.microedition.io package which -if I interpret the javadocs correctly- implement something akin to sockets.
(@ Anshal Patel)
I haven't quite understand your problem.
Have you succeed to transfer string to mobile phone or not?
To print on mobile phone you can create textbox and set string as it's value.
out.println can be used for debug purpose but should be removed in production.
You can create something like this:
Create textbox where user will input student name.
After submitting open http connection and send request with name as parameter to webservice (or simple page, whatever)
On server side pick student name, do the sql query on db and send roll_no in response.
On mobile retrieve response and print it into textbox.
int i = httpconnection.getResponseCode();
System.out.println("RC" + i);
if(i != 200)
throw new IOException("HTTP response code: " + i);
DataInputStream inputstream = httpconnection.openDataInputStream();
int j = (int)httpconnection.getLength();
System.out.println("Length of inputstream is :"+j);
byte abyte1 = new byte[j];
int k = inputstream.read(abyte1);
System.out.println("Length inputstream.read is :"+k);
String s = new String(abyte1,0,k);
System.out.println("string is:" + s + "******************************"+abc);
Yes, you can replace it with String object ( it's string ether way )
If you managed to get response in j2me, than only thing you need to do is to read input stream into String(or StringBuffer) and show it in textbox.
If you don't know how to do that you can do it like this