2

I created a midlet application that can import data from a data base (implemented with oracle in PC) and insert data to the same data base, so the application work very well in the emulator (Netbeans IDE).

Device is supporting MIDP 2.1 and jsr 172: http://www.mobilerated.com/nokia-5800-xpressmusic-specifications.html

What I want is connecting this application with the PC whith wifi connection, but when I try to implement this application in the phone (PDA or Smartphone like Nokia C6), its seems like that there is no connection between the midlet (in hendler terminal) and servlet (in PC) so I can't catch any response from PC.

This is the code that I used in 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();
    }
  }

I want to know what the modification that I must to do for that application work well?

Note: modified after an answer of a member of site, the same problem after changing the url with the @ip


@ip of my pc is : 192.168.1.2
and @ip of router is : 192.168.1.1
Unfortunately I don't know how to get the @ip of my cellphone.

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

}
gnat
  • 6,213
  • 108
  • 53
  • 73
  • does your phone support [JSR 172](http://stackoverflow.com/questions/tagged/jsr172) J2ME Web Services API? – gnat May 07 '12 at 20:12
  • in reality i don't know if my selphone support jsr or not , what i know is that is supporting MIDP 2.1(according to the selphone configuration of nokia expressmusic 5800), but how can i know this information – Karim Massi May 07 '12 at 21:15
  • I found this information in this website , my selphone is supporting jsr 172 http://www.mobilerated.com/nokia-5800-xpressmusic-specifications.html – Karim Massi May 07 '12 at 21:26

1 Answers1

0

Your URL is pointing to localhost, which is the local loopback interface. If you are executing this code on a cell phone, it won't indeed resolve it. Put the IP of your pc instead of "localhost"

Eugenio Cuevas
  • 10,858
  • 3
  • 29
  • 51
  • i made this configuration by creating a wirless network , and the connection between the slephoen and reouter is estabilished , the same thing for the connection between pc and router ....the same probleme still presented, no response from server – Karim Massi May 07 '12 at 12:26
  • i'm not getting any error in emulator ,but when i implement the midlet in the selphone and sending my request i get the error -33 after more time (more than 60 second) – Karim Massi May 07 '12 at 13:27
  • What is the IP of your cell phone and PC? There is no problem with the code, it is only that the URL is not correct. When you execute it on the emulator, the ip of it is the same as the computer. Could you also post the server code? – Eugenio Cuevas May 07 '12 at 13:35
  • @ip of my pc is : 192.168.1.2 – Karim Massi May 07 '12 at 13:43
  • I think everything is fine with the code, only thing you have to make sure is that your phone can resolve the URL `192.168.1.2`. Are you able to make a ping from the phone to the PC? Can you query that URL from another PC in the same wifi lan? – Eugenio Cuevas May 08 '12 at 13:42
  • I'm not able to make a ping from my phone to the PC , i try to ping to my phone from an other PC in same wifi lane but it's failed , but when i succed to ping the router and entering the principal page of router . there is an point that i not sure that can affect the good worck of this connection ,if the configuration in midlet is different from the phone configuration , is that point affect th connection between the midlet and servlet? – Karim Massi May 09 '12 at 14:05
  • Then that is the problem, the code is just fine. Once you can ping the PC from the phone and way back, it will work – Eugenio Cuevas May 09 '12 at 14:18
  • no result , just the error code -33 , i want to know how to make the same phone configuration in midlet configuration .and thanks you very mutch for your response , it's all very helpfull . – Karim Massi May 09 '12 at 15:12
  • i want also know if i must make some modification in oracle data base to let remote user to acess to database ? – Karim Massi May 09 '12 at 15:33
  • thanks a lot all of you, i fount where is the probleme , i changed the router with an other configuration , and i work fine , i can acess to data base very well , but when a want to change the router to an other router with initializing configuration it does'nt work any more , so i try and try to do routing the router but no way.i w'ld like to use routter (sagem fast 3304) – Karim Massi May 10 '12 at 16:58