This week's book giveaway is in the Web Services forum.
We're giving away four copies of Microservices in Action and have Morgan Bruce & Paulo A. Pereira on-line!
See this thread for details.
Win a copy of Microservices in Action this week in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Transaction error(Invalid cursor state)  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!