2013-03-13 1 views
0

이것은 블랙 베리 자바 이클립스 플러그인의 코드입니다. 웹 서비스를 호출하여 _firstName, _lastName, address, mobileNumber와 같은 아래에 언급 된 필드를 저장하려면이 코드에서 webservice를 호출 할 수 있습니까? 이 코드. 데이터베이스에 대해 말씀해 주시고 어떻게 블랙 베리 애플리케이션에서 데이터베이스를 설정할 수 있습니까? 예를 들어, 제 아이디, 성, mobilenumebr 및 주소가있는 데이터베이스를이 데이터베이스에 저장해야합니다. 웹 서비스를 호출, pls 나에게 몇 가지 아이디어 또는 webservices에 대한 코드와 블랙 베리 응용 프로그램에 특정 데이터베이스를 설정하십시오. 미리 감사는블랙 베리 네이티브 응용 프로그램에서 웹 서비스를 호출하는 방법

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); 
     } 

    } 

답변

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"); 
    } 
관련 문제