0

これは、Blackberry Java Eclipse プラグインの私のコードです。このコードで Web サービスを呼び出して、このコードから Web サービスを呼び出して、データベースに _firstName 、_lastName 、address、mobileNumber などの以下のフィールドを格納するにはどうすればよいですか。データベースについて教えてください。BlackberryアプリケーションでWebサービスを呼び出すために、Blackberryアプリケーションでデータベースを設定する方法を教えてください。つまり、私のUIデザインでは、姓、名、携帯番号、住所を持っています。このフィールドをデータベースに保存する必要がありますwebservice、pls は webservices のアイデアやコードを教えてくれ、blackberry アプリケーションに固有のデータベースを設定します。前もって感謝します

  package mypackage;
    import net.rim.device.api.database.Database;
    import net.rim.device.api.database.DatabaseFactory;
    import net.rim.device.api.database.Statement;
    import net.rim.device.api.io.URI;
    import net.rim.device.api.ui.DrawStyle;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.FieldChangeListener;
    import net.rim.device.api.ui.component.BasicEditField;
    import net.rim.device.api.ui.component.ButtonField;
    import net.rim.device.api.ui.component.DateField;
    import net.rim.device.api.ui.component.Dialog;
    import net.rim.device.api.ui.component.LabelField;
    import net.rim.device.api.ui.component.RadioButtonField;
    import net.rim.device.api.ui.component.RadioButtonGroup;
    import net.rim.device.api.ui.component.RichTextField;
    import net.rim.device.api.ui.component.SeparatorField;
    import net.rim.device.api.ui.container.HorizontalFieldManager;
    import net.rim.device.api.ui.container.MainScreen;
    import net.rim.device.api.ui.container.VerticalFieldManager;

    public final class CreateProfileScreen extends MainScreen {
        Database d;
        BasicEditField _firstName = new BasicEditField("First Name:", "");

        BasicEditField _lastName = new BasicEditField("Last Name:", "");

        BasicEditField mobileNumber = new BasicEditField("MobileNumber:", "");

        BasicEditField address = new BasicEditField("Address:", "");


        public CreateProfileScreen() {
            HorizontalFieldManager btns = new HorizontalFieldManager(
                    HorizontalFieldManager.FIELD_HCENTER);

            ButtonField save = new ButtonField("Save", ButtonField.FIELD_HCENTER);
            // adding these objects to the Blackberry Application.
            VerticalFieldManager vfm = new VerticalFieldManager(
                    VerticalFieldManager.FIELD_LEFT);
            vfm.add(_firstName);

            vfm.add(new SeparatorField());

            vfm.add(_lastName);
            vfm.add(new SeparatorField());
            vfm.add(mobileNumber);
            vfm.add(new SeparatorField());
            RadioButtonGroup rbg = new RadioButtonGroup();
            vfm.add(new RadioButtonField("Male", rbg, true));
            vfm.add(new RadioButtonField("Female", rbg, false));
            vfm.add(new SeparatorField());

            vfm.add(new DateField("DOB:", System.currentTimeMillis(),
                    DateField.DATE | DrawStyle.LEFT));
            vfm.add(new SeparatorField());
            vfm.add(address);
            vfm.add(new SeparatorField());
            vfm.add(save);

            add(vfm);

            FieldChangeListener btnlistener = new FieldChangeListener() {

                public void fieldChanged(Field field, int context) {
                    // Open a new screen

                    String fname = _firstName.getText();
                    String lname = _lastName.getText();
                    String mobno = mobileNumber.getText();
                    String addr = address.getText();

                    if (fname.length() == 0 || lname.length() == 0)
                        Dialog.alert("firstname and lastname is mandatory!");
                    LabelField title = new LabelField("SQLite Insert Data "
                            + "Schema Sample", LabelField.ELLIPSIS
                            | LabelField.USE_ALL_WIDTH);
                    setTitle(title);
                    add(new RichTextField("Attempting to insert data into "
                            + "MyTestDatabase.db on the SDCard."));
                    try {
                        URI myURI = URI.create("D:///db/" + "MyTestDatabase2.db");
                        d = DatabaseFactory.open(myURI);

                        Statement st = d
                                .createStatement("INSERT INTO People(Name,Age) "
                                        + "VALUES ('John',37)");
                        st.prepare();
                        st.execute();
                        st.close();
                        d.close();
                        add(new RichTextField("inserting data successful"));
                        System.out.println("inserting data successful");
                    } catch (Exception e) {
                        System.out.println(e.getMessage());
                        e.printStackTrace();
                    }

                }

            };
            save.setChangeListener(btnlistener);
        }

    }
4

1 に答える 1

0

これを試して -

try {

        String httpURL="www.your url.com/register?fname="+fname_value+"&lname="+lname_value+"&mobno ="+no_value+"&addr="+address_value;
        HttpConnection httpConn;
        httpConn = (HttpConnection) Connector.open(httpURL);
        httpConn.setRequestMethod(HttpConnection.POST);
        DataOutputStream _outStream = new DataOutputStream(httpConn.openDataOutputStream());
        byte[] request_body = httpURL.getBytes();
        for (int i = 0; i < request_body.length; i++) {
            _outStream.writeByte(request_body[i]);
        }
        DataInputStream _inputStream = new DataInputStream(
        httpConn.openInputStream());
        StringBuffer _responseMessage = new StringBuffer();
        int ch;
        while ((ch = _inputStream.read()) != -1) {
            _responseMessage.append((char) ch);
        }
        String res = (_responseMessage.toString());
        String responce = res.trim();

        Dialog.alert(responce);

        httpConn.close();


    }catch (Exception e) {
        Dialog.alert("Error");
    }
于 2013-03-13T13:05:41.227 に答える