I am using
jsp with Oracle.Whenever i use the code "con.setAutoCommit(false)" i get a runtime exception saying invalid transaction state.Without it everything works fine except ofcourse there is no transaction support.I am using multiple statements in the jsp.I have included the code fragment below.what could be the possible reasons.Please help.Thanks in advance.
//Import driver and make a connection
Class.forName(DRIVER);
con=DriverManager.getConnection(URL,"reswebp","reswebp");
//con.setAutoCommit(false);
//create statement
stmt =con.createStatement();
//create sql statements
sqlteam="insert into reswebp.Team values('"+teamid+"',"+null+","+null+",'"+organization+"')";
sqlrequestedby="insert into reswebp.Requestedby values('"+lanid+"','"+firstname+"','"+lastname+"','"+phonenumber+"','"+emailaddress+"','"+stopcode+"','"+teamid+"')";
sqlteam2="select * from reswebp.Team";
sqlrequestedby2="select * from reswebp.Requestedby";
sqlrequest2="select * from reswebp.Request order by request_id";
//execute select statement on team table to create resultset
ResultSet rsteam=stmt.executeQuery(sqlteam2);
//check the resultset to see if the team is new, and set the flag variable isteamnew
while(rsteam.next())
{
String teamid2=rsteam.getString(1);
if(teamid2.equalsIgnoreCase(teamid))
isteamnew=false;
}
rsteam.close();
//execute select statement on requestedby table to create resultset
ResultSet rsrequestedby=stmt.executeQuery(sqlrequestedby2);
//check the resultset to see if the lanid is new and set the flag variable islanidnew
while(rsrequestedby.next())
{
lanid2=rsrequestedby.getString(1);
if(lanid.equalsIgnoreCase(lanid2))
islanidnew=false;
}
rsrequestedby.close();
//Creat the sql insert statement for the request table
sqlrequest= "insert into reswebp.Request values(no_seq.nextval,'"+tofsupport+"',to_date('"+currdate+"','MM/DD/YYYY'),'Pending',"+siteid+",'"+comments+"',to_date('"+requestidate+"','MM/DD/YYYY'),'"+lanid+"','"+requestname+"','"+requestip+"',"+null+","+null+","+null+","+null+","+null+","+null+","+null+","+null+")";
//Clear the statements of any existing batches
stmt.clearBatch();
//If team is new add the team
if(isteamnew)stmt.addBatch(sqlteam);
//if lanid is new add the lanid
if(islanidnew)stmt.addBatch(sqlrequestedby);
//add request finally
stmt.addBatch(sqlrequest);
//execute the batch and check the update counts
int[] counts=stmt.executeBatch();
boolean allgood=true;
for(int i=0;i<counts.length;i++)
if(counts[i]!=1)
allgood=false;
//commit or rollback the transaction depending on successfull execution of the batch
if(allgood)
{
con.commit();
//finally get the request id for the new request
ResultSet forid=stmt.executeQuery(sqlrequest2);
while(forid.next())
{
requestid=forid.getLong(1);
}