Database query rollback to a savepoint fails

mikelmao11

New Member
\[code\]<body><%String ide=request.getParameter("q");int num=0;if(ide!=null) num=Integer.parseInt(ide);String vegg=request.getParameter("vegetables");int newe=0; Connection cnt1=null;try{String connectionURL = "jdbc:mysql://localhost:3306/emandi";Class.forName("com.mysql.jdbc.Driver"); cnt1 = DriverManager.getConnection(connectionURL, "root", "root"); cnt1.setAutoCommit(false); cnt1.commit();Statement stmt1 = cnt1.createStatement();Savepoint mySavepoint = cnt1.setSavepoint("sp1");ResultSet resultSet = stmt1.executeQuery("select Quantity from data where vegetables='"+vegg+"' ");if(resultSet.next()){ newe=resultSet.getInt(1);}int newvalue=http://stackoverflow.com/questions/15675920/newe-num;//PreparedStatement statem1=cnt1.prepareStatement("update data set Quantity="+newvalue+" where vegetabels='"+vegg+"' ");//statem1.execute();stmt1.executeUpdate("update data set Quantity="+newvalue+" where vegetables='"+vegg+"' ");out.println(newvalue);}catch(Exception e){out.println(e); }%><script> function disp_confirm(){var r=confirm("confirm booking?")if (r==true){ <%cnt1.commit();%> alert("booked") } else() {<%cnt1.rollback(sp1);%> alert("You pressed Cancel!") } }</script><input type="button" onclick="disp_confirm()" value="http://stackoverflow.com/questions/15675920/book"></body></html>\[/code\]I've written a JSP page to confirm booking of vegetables. All the functions are correctly working. Except the rollback to a savepoint if a user clicks cancel button.Even if the user clicks the cancel button, rollback option is not working. Any advice?
 
Back
Top