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