SQL Server 2000 JDBC驱动程序事务出错

fengz 2002-10-31 11:40:21
大虾帮忙


我用SQL Server 2000 JDBC驱动程序 开始一事务,
程序出错如下提示:
ava.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection while in manual transaction mode.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.setupImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.<init>(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.<init>(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.prepareStatement(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.prepareStatement(Unknown Source)

程序如下:
try {
DatabaseConnection.beginTrans( conn );
//begin trans
String strSql = "insert into ddd (name) values ('yzf')";
Statement stmt = conn.createStatement();
int rows = stmt.executeUpdate(strSql);
if(rows != 1) throw new Exception("error");


PreparedStatement ps = conn.prepareStatement( strSql );
strSql = "select @@IDENTITY ";
ResultSet rsFid = stmt.executeQuery(strSql);
int identity= 0;
if (rsFid.next()) identity = rsFid.getInt(1);
System.out.println(identity);
strSql = "insert into ddd (name) values ('BBBB')";
stmt = conn.createStatement();
rows = stmt.executeUpdate(strSql);
if(rows != 1) throw new Exception("error");

DatabaseConnection.commitTrans( conn ); //commit trans
} catch( Exception ex ) {
ex.printStackTrace();
DatabaseConnection.rockbackTrans( conn );

}
...全文
37 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
binriyue 2002-10-31
  • 打赏
  • 举报
回复
DatabaseConnection.setAutoCommit(false);
insert;
update;
delete;
......
DatabaseConnection.setAutoCommit(true);

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧