我想保障事务的原子性让两次更新数据库的操作都能同时正确的进行或者错误时都不更新;
我在设置Connection的etAutoCommit为false然后进行二个更新操作。但在执行过程中老出现错误,代码和错误提示如下:
<%@ page import="java.sql.*" %>
<%
int newId = Integer.parseInt(request.getParameter("newId"));
int id = Integer.parseInt(request.getParameter("id"));
int rootId = Integer.parseInt(request.getParameter("rootId"));
String title = request.getParameter("id");
String cont= request.getParameter("cont");
%><%
String dbURL = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=MyData";
String user = "sa";
String password = "mypassword";
Connection conn = null;
Statement stmt = null;
PreparedStatement pstmt = null;
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
conn = DriverManager.getConnection(dbURL,user,password);
conn.setAutoCommit(false);
String sql = "insert into article values(?,?,?,?,?,'2007-11-11',0)";
pstmt = conn.prepareStatement(sql);pstmt.setInt(1,newId);
pstmt.setInt(2,id);
pstmt.setInt(3,rootId);
pstmt.setString(4,title);
pstmt.setString(5,cont);
pstmt.executeUpdate();stmt = conn.createStatement();//提示错误出现在这
stmt.executeUpdate("update article set isleaf = 1 where id =" +id);
//pstmt.addBatch("update article set isleaf = 1 where id =" +id);
//pstmt.executeBatch();conn.commit();conn.setAutoCommit(true);response.sendRedirect("lod.jsp");
%>org.apache.jasper.JasperException: Exception in JSP: /ReplyOk.jsp:3431: pstmt.setString(5,cont);
32: pstmt.executeUpdate();
33: 
34: stmt = conn.createStatement();
35: stmt.executeUpdate("update article set isleaf = 1 where id =" +id);
36: //pstmt.addBatch("update article set isleaf = 1 where id =" +id);
37: //pstmt.executeBatch();
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection while in manual transaction mode.
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
org.apache.jsp.ReplyOk_jsp._jspService(ReplyOk_jsp.java:104)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection while in manual transaction mode.
com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
com.microsoft.jdbc.base.BaseConnection.getImplConnection(Unknown Source)
com.microsoft.jdbc.base.BaseStatement.setupImplConnection(Unknown Source)
com.microsoft.jdbc.base.BaseStatement.<init>(Unknown Source)
com.microsoft.jdbc.base.BaseConnection.createStatement(Unknown Source)
com.microsoft.jdbc.base.BaseConnection.createStatement(Unknown Source)
org.apache.jsp.ReplyOk_jsp._jspService(ReplyOk_jsp.java:76)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)请帮忙解决一下,或者能指点我到底该怎样达到我的那个目的。先谢谢各位!!!