<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>事务处理程序</title>
</head>
<body>
<table width="372" border="1" align="center" cellspacing="0">
<tr>
<td><div align="center">事务处理程序</div></td>
</tr>
<tr>
<td>
<%
String sqlString1="update userinfo set age=21 where name like '12%'";
String sqlString2="update userinfo set age=22 where name like '吴%'";
//String sqlString1="select userinfo where name like '冼%'";
//String sqlString2="select userinfo where name like '吴%'";
Connection con;
Statement sql;
// ResultSet rs;
//String sqlString;
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://MICROSOF-BJER9M:1433;DatabaseName=basesql","sa","12345");
try
{
con.setAutoCommit(false);
sql=con.createStatement();
sql.executeUpdate(sqlString1);
sql.executeUpdate(sqlString2);
con.commit();
out.print("事务提交成功,执行两条SQL语句!");
con.close();
}
catch(SQLException e)
{
con.rollback();
out.print("事务操作不成功,事务已回滚!");
}
%>
</td>
</tr>
</table>
</body>
</html>
我的数据库中只有两条记录,一条为冼某某(name),21(age),另一条为吴某某(name),22(age)
为什么我执行的时候,输出的结果"是事务提交成功,执行两条SQL语句!"
我原以为是"事务操作不成功,事务已回滚!",因为我的记录中并没有12**的记录,谁能解释一下?
[此贴子已经被作者于2006-8-14 9:38:20编辑过]