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
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
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
;)
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.