BaseBatchUpdateException SQLServer 2000 Driver for JDBC 必须声明变量
public void executeBat(String[] sql) throws SQLException {
String sqls="";
for (int i = 0; i < sql.length; i++) {
log.info("bantch execute Bat[" + String.valueOf(i) + "]: "
+ sql[i]);
sqls+=" "+sql[i];
}
vertifyDataSource();//检测con是否为空
boolean wasAutoCommit = con.getAutoCommit();
try {
con.setAutoCommit(false);
Statement stmt = con.createStatement();
for (int i = 0; i < sql.length; i++)
stmt.addBatch(sql[i]);
stmt.executeBatch();
con.commit();
stmt.close();
System.out.print("xxx");
} catch (SQLException ex) {
con.rollback();
log.error(ex.getMessage());
System.err.print(ex);
throw new SQLException(ex.getMessage());
} catch (Exception ex) {
con.rollback();
log.error(ex.getMessage());
throw new SQLException(ex.getMessage());
}
con.setAutoCommit(wasAutoCommit);
}
当 执行
String[] sql=new String[2];
sql[0]="declare @id int";
sql[1]="select @id=id from user where name='xxxx'"
executeBat(sql);
时抛出com.microsoft.jdbc.base.BaseBatchUpdateException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]必须声明变量 '@id'