• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

array to database using servlets from a midlet

 
sachin sav
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am in the process of developing a small application which users use to order food at a restaurant using the mobile phone. The food items will be hard coded as a multiple choice group in the midlet. Using the getSelectedFlags() I am able to store the selected options in an array. However I would like to store these in an Access database. Is it possible to send the contents of the array to a database using servlets. I have very limited knowledge about connecting servlets to midlets and writing servlets. In this instance would I use a GET and append the URL with the arrayname or would POST be easier.
One other small thing when testing using System.out.println to see if the array was being populated only true or false was shown with no details about the item selected. Using the getString () I was able to display the name of the item being selected. How can I ensure that only selected items are stored in the array and those that are not selected are not in the array. I will apprecate any help
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class FormPizzaexp extends Form implements CommandListener {

private ChoiceGroup pizzaexpMenu;
private MainScreen midlet;
private Command cmdBack;
private Command cmdSelect;

public FormPizzaexp (String title, MainScreen midlet ){

super (title);
this.midlet = midlet;
cmdBack = new Command("Back", Command.BACK, 1);
cmdSelect = new Command("Select",Command.OK, 2);
pizzaexpMenu = new ChoiceGroup ("What would you like to Order?", Choice.MULTIPLE,
new String [] {"ANTIPIZZE", "Garlic Bread �1.95", "Bruschetta �3.25", "Baked Dough Balls �1.95", "SALADS AND VARIATIONS", "Mozzarella and Tomato Salad �6.45", "Lasagne Pasticcate �7.10", "Tortellini �7.10", "PIZZE", "Margherita �4.95", "American Hot �7.70", "Soho Pizza �6.95", "Sloppy Giussepe �7.15", "WINE", "House White Bottle 75cl �10.95", "Half House White Bottle 37.5cl �5.95", "House Red Bottle 75cl �10.95", "Half House Red Bottle 37.5cl �5.95", "SOFT DRINKS", "Coke �1.65", "Sprite �1.65", "Mineral Water �1.00", "Apple Juice �1.65", "DESSERTS", "Choclate Fudge Cake �3.85", "Tiramisu �3.85", "Vanilla Ice Cream �2.10"}, null);
append(pizzaexpMenu);
addCommand(cmdBack);
addCommand(cmdSelect);
setCommandListener(this);

}

public void commandAction(Command c, Displayable s) {
if (c == cmdBack)
midlet.displayMainForm ();
else if (c == cmdSelect){
boolean selected[] = new boolean [pizzaexpMenu.size()];
pizzaexpMenu.getSelectedFlags(selected);

for (int i=0; i<pizzaexpMenu.size(); i++)
System.out.println (pizzaexpMenu.getStrin(i) +(selected[i]));
}

}


}
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For starters, check out these samples:
http://developers.sun.com/techtopics/mobility/midp/samples/#nw
http://www.corej2me.com/DeveloperResources/sourcecode/networking/callServletGET/index.shtml
http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20875127.html
http://www.wirelessdevnet.com/channels/java/features/j2me_http.phtml
Basically, the HTTP GET with request parameters appended to the URL will work fine as long as you take care of the URL being correctly encoded (no illegal characters) and short enough (some phones and/or gateways have trouble with long URLs, for example, over 255 characters). POST is more reliable but may require a few lines more code than the GET approach.
[ March 29, 2004: Message edited by: Lasse Koskela ]
 
sachin sav
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks for all your help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic