脚本内容(一): if exists(select * from TUser where userid = N'01') begin create table TUser ( userid varchar(10), userName varchar(50), userAge varchar(4), userAddress varchar(500) ) end
脚本内容(二): if not exists(select * from TUser where userid = N'01') begin create table TUser ( userid varchar(10), userName varchar(50), userAge varchar(4), userAddress varchar(500) ) end
细心的朋友,应该知道,这第二个脚本就比前多一个"not"吧? 现在就取两个脚本的字符串内容,分别为:String sql1 和 String sql2, 现在分别执行: execute(sql1);//此处执行成功,并任何异常 execute(sql2);//此处执行失败,控制台异常信息是: Exception in thread "main" com.microsoft.jdbc.base.BaseBatchUpdateException: [Microsoft][SQLServer 2000 Driver for JDBC]Statements that produce result sets are not allowed in batch commands. at com.microsoft.jdbc.base.BaseStatement.executeBatchEmulation(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.executeBatch(Unknown Source) ...