BaseBatchUpdateException SQLServer 2000 Driver for JDBC 必须声明变量

xiongdamao 2008-04-23 09:03:23
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'
...全文
58 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiongdamao 2008-04-23
  • 打赏
  • 举报
回复
我用jtds就好用
wlzhao 2008-04-23
  • 打赏
  • 举报
回复
JDBC batch update 只支持DDL。建议用存储过程
xiongdamao 2008-04-23
  • 打赏
  • 举报
回复
我用executeBatch()为什么抛出Batch Update 呢?
wlzhao 2008-04-23
  • 打赏
  • 举报
回复
Batch Update 只允许insert,update,delete
xiongdamao 2008-04-23
  • 打赏
  • 举报
回复
con通过struts的getDataSource(request)得到

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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