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 );
}