<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=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="book">
</body>
</html>
我写了一个JSP页面来确认蔬菜的预订。所有功能都正常工作。如果用户单击取消按钮,则退回到保存点。 即使用户单击取消按钮,回滚选项也不起作用。有什么建议吗?
答案 0 :(得分:0)
根本不建议你做什么。而且你不能像Javascript事件一样调用Java代码。