how to avoid java.lang.IllegalStateException:URGENT

hi all,

I am working on a mobile application,in which i am getting the details from database server by sending a query from the MIDlet.

I am facing the following problem,please give some suggestions how to fix that Exception

java.lang.IllegalStateException:Write attempted after request finished

This was the Exception i am getting when i am opening and getting the data can anybody please give me some suggestions regarding that.

thanks in advance

lakshman

[509 byte] By [lakshmanraoba] at [2007-10-2 5:50:14]
# 1
give us some code...
deepspacea at 2007-7-16 1:59:37 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2

hi,

thanks for your response,I am sending the code in which i am sending and receiving the Input/OuputStream

public class DbServ implements Runnable

{

Graphics g;

private boolean iwrunning;

public DbServ()

{

try{

iwrunning=true;

Thread tiw=new Thread(this);

tiw.start();

}catch(Exception e){}

}

public void run()

{

if(checkRegister<1)

{

try{

if(os==null)

{

os = con.openOutputStream();

}

String str=null;

if(paintCommand.equals("REGISTER2"))

{

System.out.println("HIT");

int ssNo = Integer.parseInt(reg3Text,10);

int phoneNo = Integer.parseInt(reg4Text,10);

str ="Insert into Liberty.tblCustomerMaster(strFirstName,strLastName,intSsNo,intPhoneNo,strUserId,strPsd,strCpsd) values('"+reg1Text+"','"+reg2Text+"',"+ssNo+","+phoneNo+",'"+reg5Text+"','"+reg6Text+"','"+reg7Text+letChoose+"')";

}

if(paintCommand.equals("LOGIN2")||paintCommand.equals("LOGIN1"))

{

str = "select strUserId,strPsd from Liberty.tblCustomerMaster";

}

os.write(str.getBytes());

os.flush();

str = null;

is = con.openDataInputStream();

int ch;

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

{

sb.append((char) ch);

}

opFrmServ = sb.toString();

}catch(Exception e){

System.out.println("the problem is..."+e);

}

}// check for the number of additions to the ouputstream

++checkRegister;

}

}

please give me some suggestions

lakshmanraoba at 2007-7-16 1:59:37 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3
Do you get this the second time the thread runs?Btw, it's not very wise (to say it mildly) to put raw SQL statements in a http request!
deepspacea at 2007-7-16 1:59:37 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4

hi,

Excatly what you said was correct.I am getting the Exception in the second attempt.

How to rectify it?.

I thought sending the SQL statement from the user side was an wise decision,Because In my application i have to do some insertions and some times select statements.

So I thought this procedure is help full.Please give me some suggestion in doing those operations in another way.

thanks in advance

lakshman

lakshmanraoba at 2007-7-16 1:59:37 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5

;)

Well, you'll need to open a new http connection to your servlet every time you run the thread. You don't to that, and the second time you open the streams, it will go wrong.

About the sql: sure it's easy to implement, but it's far from save! anyone calling your servlet will just be able to do stuff like:

Delete * from babla

...or even

Drop blablabla

Some things to consider:

- use at least http authentication

- as with a real a website, never use SQL directly. you can better use commands to read or insert data into a database.

deepspacea at 2007-7-16 1:59:37 > top of Java-index,Java Mobility Forums,Java ME Technologies...