这样的做法不是很好,据JDK所描述的,使用Batch执行SQL的话可能是遇到出错时,跳过该执行语句,继续下一个SQL语句的执行,所以不要用Batch,不过效率也会差一些

解决方案 »

  1.   

    看看API文档中的说明,executeBatch方法返回一个数组,如果一条语句执行失败,那么就会有一个错误代码存到数组中,你检测执行完的数组就可以了。public int[] executeBatch()
                       throws SQLExceptionSubmits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts. The int elements of the array that is returned are ordered to correspond to the commands in the batch, which are ordered according to the order in which they were added to the batch. The elements in the array returned by the method executeBatch may be one of the following: 
       A number greater than or equal to zero -- indicates that the command was processed successfully and is an update count giving the number of rows in the database that were affected by the command's execution    A value of SUCCESS_NO_INFO -- indicates that the command was processed successfully but that the number of rows affected is unknown   If one of the commands in a batch update fails to execute properly, this method throws a BatchUpdateException, and a JDBC driver may or may not continue to process the remaining commands in the batch. However, the driver's behavior must be consistent with a particular DBMS, either always continuing to process commands or never continuing to process commands. If the driver continues processing after a failure, the array returned by the method BatchUpdateException.getUpdateCounts will contain as many elements as there are commands in the batch, and at least one of the elements will be the following: 
    A value of EXECUTE_FAILED -- indicates that the command failed to execute successfully and occurs only if a driver continues to process commands after a command fails 
    A driver is not required to implement this method. The possible implementations and return values have been modified in the Java 2 SDK, Standard Edition, version 1.3 to accommodate the option of continuing to proccess commands in a batch update after a BatchUpdateException obejct has been thrown.