HTTP operation error on midlet

hi all fellows!

i've got a problem in MIDlet and servlet connection.

i've created a midlet and installed its jad in mobile phone, on PC i run the servlet and midlet, it works properly, but when i run application on the mobile phone, it says "error in HTTP operation".

can anybody help me? i m using this first time.

[342 byte] By [Muhammada] at [2007-11-27 9:34:30]
# 1
can you show us the code where you're creating the connection please...
suparenoa at 2007-7-12 22:58:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2

her is my code.

this is on MIDlet side

StringBuffer sb = new StringBuffer();

try {

HttpConnection c = (HttpConnection) Connector.open(url);

c.setRequestProperty(

"User-Agent","Profile/MIDP-1.0, Configuration/CLDC-1.0");

c.setRequestProperty("Content-Language","en-US");

DataOutputStream os =

(DataOutputStream)c.openDataOutputStream();

os.writeUTF(selection.trim());

os.writeUTF(user.trim());

os.writeUTF(pwd.trim());

os.writeUTF(Store.trim());

os.flush();

os.close();

// Get the response from the servlet page.

DataInputStream is =(DataInputStream)c.openDataInputStream();

int ch;

sb = new StringBuffer();

while ((ch = is.read()) != -1) {

sb.append((char)ch);

}

if(sb.length()==0)

showAlert("Login not Successful. Try Again or Subscribe if You are not Authorised");

else

{

showAlert(sb.toString());

storeshow=true;

}

is.close();

c.close();

} catch (Exception e) {

showAlert(e.getMessage());

}

}

/* This method takes input from user like db,user and password and pass to servlet */

public void connectDb(String user,String pwd) {

this.user = user;

this.pwd = pwd;

}

and this is on servlet side

Connection conn = null;

ResultSet rs=null;

Statement stmt;

DataInputStream in = new DataInputStream(

(InputStream)request.getInputStream());

try

{

conn = DriverManager.getConnection(

"jdbc:derby://localhost:1527/RetailDB",

"bilal",

"bilal");

String user = in.readUTF();

String pwd = in.readUTF();

stmt= conn.createStatement();

rs = stmt.executeQuery("SELECT * FROM RetailUser WHERE UserName='"+user+"' AND Password='"+pwd+"'");

while(rs.next())

{

out.println(rs.getString("UserName") + " || " + rs.getString("Phone") );

}

}

catch(SQLException e)

{

out.println("SQLException: " + e.getMessage() + "
");

while((e = e.getNextException()) != null)

out.println(e.getMessage() + "
");

}

finally

{

//Clean up resources, close the connection.

if(conn != null)

{

try

{

conn.close();

}

catch (Exception ignored) {}

}

}

in.close();

out.close();

wud this be because of setting request property in MIDlet? i tried this on Nokia 6280, but shows "Error in HTTP operation".

Muhammada at 2007-7-12 22:58:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3

here is my code.

this is on MIDlet side

StringBuffer sb = new StringBuffer();

try {

HttpConnection c = (HttpConnection) Connector.open(url); c.setRequestProperty( "User-Agent","Profile/MIDP-1.0, Configuration/CLDC-1.0");

c.setRequestProperty("Content-Language","en-US"); DataOutputStream os = (DataOutputStream)c.openDataOutputStream();

os.writeUTF(user.trim());

os.writeUTF(pwd.trim());

os.writeUTF(Store.trim());

os.flush();

os.close();

// Get the response from the servlet page.

DataInputStream is =(DataInputStream)c.openDataInputStream();

int ch;

sb = new StringBuffer();

while ((ch = is.read()) != -1)

{ sb.append((char)ch); }

if(sb.length()==0) showAlert("Login not Successful. Try Again or Subscribe if You are not Authorised");

else

{ showAlert(sb.toString()); storeshow=true; }

is.close();

c.close();

}

catch (Exception e)

{

showAlert(e.getMessage());

}

}

/* This method takes input from user like db,user and password and pass to servlet */

public void connectDb(String user,String pwd)

{

this.user = user;

this.pwd = pwd;

}

and this is on servlet side

Connection conn = null;

ResultSet rs=null;

Statement stmt;

DataInputStream in = new DataInputStream( (InputStream)request.getInputStream());

try

{

conn = DriverManager.getConnection( "jdbc:derby://localhost:1527/RetailDB", "bilal", "bilal");

String user = in.readUTF();

String pwd = in.readUTF();

stmt= conn.createStatement();

rs = stmt.executeQuery("SELECT * FROM RetailUser WHERE UserName='"+user+"' AND Password='"+pwd+"'");

while(rs.next())

{

out.println(rs.getString("UserName") + " || " + rs.getString("Phone") );

}

}

catch(SQLException e)

{

out.println("SQLException: " + e.getMessage() + "");

while((e = e.getNextException()) != null)

out.println(e.getMessage() + "");

}

finally

{

//Clean up resources, close the connection.

if(conn != null)

{

try { conn.close();

}

catch (Exception ignored)

{}

}

}

in.close();

out.close();

wud this be because of setting request property in MIDlet? i tried this on Nokia 6280, but shows "Error in HTTP operation".

Muhammada at 2007-7-12 22:58:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4
hi all fellows.shud i change the access point settings of my nokia handset to access the servlet?but i dont know what settings i need to set to get my application working.please help if you can.thanks.
Muhammada at 2007-7-12 22:58:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5
what is the value of url?
suparenoa at 2007-7-12 22:58:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 6

Yeah, is the url correct in mobile device you are testing?

I mean

conn = DriverManager.getConnection( "jdbc:derby://localhost:1527/RetailDB", "bilal", "bilal");

works on a emulator when database is on the same machine as emulator but on phone it needs to point to the machine that has the DB..

Zangaza at 2007-7-12 22:58:50 > top of Java-index,Java Mobility Forums,Java ME Technologies...