2012-05-07 13 views
2

私は、データベース(PCのOracleで実装)からデータをインポートし、同じデータベースにデータを挿入できるMIDletアプリケーションを作成しました。エミュレータ(Netbeans IDE)。midletをサーブレットに接続するための正しい構成は何ですか

デバイスは、MIDP 2.1とJSR 172をサポートしている:http://www.mobilerated.com/nokia-5800-xpressmusic-specifications.html

私はWiFi接続whith PCでこのアプリケーションを接続しているしたいが、私はこの携帯電話でアプリケーション(PDAやスマートフォンのNokia C6などを実装しようとすると、 )、それは(私はPCからの応答をキャッチすることはできませんので、(hendler端末の)midletとサーブレット(PCの)の間に接続がないように思えます。

private void doInsertDataEtat() throws IOException 
    { 
    HttpConnection http = null; 
    InputStream iStrm = null; 


    url ="http://192.168.1.2:8080/TESTWEB/InsertDataEtat" +"?"+"loconum="+List_Num.getString(List_Num.getSelectedIndex()).substring(0, 4) +"&"+"datedevisite="+nbrdate+"&"+"heuredebut="+dateFieldAc.getDate().toString().substring(11,16)+"&"+"etat="+Etatfinal.getString(Etatfinal.getSelectedIndex()).replace(' ', '+') +"&"+"observationetat="+observationEtat.getString().replace(' ', '+') +"&"+"dureevisite="+dureevisite; 

    try 
    { 
     // Create the connection 
     http = (HttpConnection)Connector.open(url); 
     System.out.println("url: " + url);   

     // 2) Get header information 
     if (http.getResponseCode() == HttpConnection.HTTP_OK) 
     { 

     // afficher les données recus de la servlet par la methode get 

      System.out.println("INSERTION REUSSITE"); 


     } 
     }catch(Exception e){ 
      e.printStackTrace(); 
      Alert alert = new Alert("Erreur de Connexion", "Désolé , il y a une erreur au nivau de la connextion au serveur \n"+e.getMessage(), null, AlertType.ERROR); 
      alert.setTimeout(Alert.FOREVER); 
      display.setCurrent(alert); 
     } 
    finally{ 
     // detruire les variable apres l'utilisation 
     if (iStrm != null) 
     iStrm.close(); 
     if (http != null) 
     http.close(); 
    } 
    } 

私はよく、そのアプリケーションの作業のために行うには、私がしなければならない何の変更を知りたい:

これは、私はミッドレットで使用されるコードはありますか?

注:サイトのメンバー、@ip私のPCの


@ipでURLを変更した後、同じ問題の解答後に変更がある:192.168.1.2
との@ipルータは:192.168.1.1
残念ながら私は自分の携帯電話の@ipを取得する方法がわかりません。

@WebServlet(name = "InsertDataEtat", urlPatterns = {"/InsertDataEtat"}) 
public class InsertDataEtat extends HttpServlet { 

    public String loconum,observationEtat,datevisite,heuredebut,etat,dureevisite; 
    public void doGet(HttpServletRequest request, HttpServletResponse response) 
      throws ServletException, IOException { 
     response.setContentType("text/plain"); 
     PrintWriter out = response.getWriter(); 
     try 
     { 

       //parametre passer du midlet a la servlet par la methode GET 
        loconum = request.getParameter("loconum"); 
        etat = request.getParameter("etat").replace('+', ' '); 
        datevisite = request.getParameter("datedevisite"); 
        heuredebut = request.getParameter("heuredebut"); 
        observationEtat = request.getParameter("observationetat").replace('+', ' '); 
        observationEtat = observationEtat.replace("'", "''"); 
        dureevisite=request.getParameter("dureevisite"); 


            String sql="INSERT INTO ETAT VALUES('"+loconum+"','" 
         +datevisite+"','"+observationEtat+"','"+etat+"','"+heuredebut+"','"+dureevisite+"')"; 
        System.out.println(sql); 
       //---------------------------------------------------------- 
       Class.forName("oracle.jdbc.driver.OracleDriver"); 
       Connection con=DriverManager.getConnection 
       ("jdbc:oracle:thin:@th-d3a2629a531d:1521:XE","ONCFDB","ONCFDB"); 
       Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE); 



       stmt.executeUpdate(sql); 
       System.out.println("c'est fait avec succés");  


      } 
     catch(Exception e) 
     { 
      System.out.println("ça marche pas "); 
     } 

     out.close(); 
    } 

} 
+0

あなたの電話は[JSR 172](http://stackoverflow.com/questions/tagged/jsr172)J2ME Web Services APIをサポートしていますか? – gnat

+0

実際に私の携帯電話がjsrをサポートしているかどうかわかりませんが、MIDP 2.1(nokia expressmusic 5800のselphone設定に従います)をサポートしていますが、私はこの情報をどのように知ることができますか –

+0

このウェブサイトでは、私の携帯電話はjsrをサポートしています172 http://www.mobilerated.com/nokia-5800-xpressmusic-specifications.html –

答えて

0

あなたのURLは、ローカルループバックインターフェイスであるlocalhostを指しています。このコードを携帯電話で実行している場合は、実際には解決されません。 "localhost"の代わりにあなたのPCのIPを入れてください

+0

私は無線ネットワークを作成することでこの設定を行いました。そして、slephoenとreouterの間の接続が確立されました、PCとルータ間の接続についても同じこと....同じ問題が依然として表示され、サーバからの応答がありません –

+0

取得しているエラーのスタックトレースを追加できますか? –

+0

私はエミュレータで何のエラーも出ていませんが、私がselphoneにミッドレットを実装し、私の要求を送信すると、もっと長い時間(60秒以上)後にエラー-33が発生します –

関連する問題