2

データベースからデータをインポートし (PC の Oracle で実装)、同じデータベースにデータを挿入できる midlet アプリケーションを作成したので、アプリケーションはエミュレーター (Netbeans IDE) で非常にうまく機能します。

デバイスは MIDP 2.1 および jsr 172 をサポートしています: http://www.mobilerated.com/nokia-5800-xpressmusic-specifications.html

私が欲しいのは、このアプリケーションをwifi接続でPCに接続することですが、このアプリケーションを電話(PDAまたはNokia C6のようなスマートフォン)に実装しようとすると、midlet(ヘンドラー端末)間に接続がないようですおよびサーブレット(PC内)なので、PCからの応答をキャッチできません。

これは私が midlet で使用したコードです:

    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 で URL を変更した後の同じ問題


私の PC の @ip は : 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();
    }

}
4

1 に答える 1

0

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

于 2012-05-07T11:56:25.203 に答える