Where The Streets Have No Name

[sampe] addBatch Query일괄실행 본문

Developement/Java

[sampe] addBatch Query일괄실행

highheat 2007. 4. 25. 16:12
PoolManager pool = PoolManager.getInstance();
Connection conn = null;
PreparedStatement pstmt = null;
   
try {
    conn = (Connection) pool.getConnection();  
   
pstmt = conn.prepareStatement("delete from neouserTable where name = ?");
   
   for (int i=0; i < daumid.length; i++) {  
       pstmt.setString (1, name[i]);
       pstmt.addBatch();
   }

 
   int results[] = pstmt.executeBatch();  
    returnValue ="true";
   
  } catch (BatchUpdateException e) {
      
//오류  발생 이전의 SQL 문에서 insert된 행 갯수를 배열로 리턴한다.
      int rsSuccessCnts[] = e.getUpdateCounts();    
      for( int i=0; i<rsSuccessCnts.length; i++ ) {
          _logger.debug( i + "번째 쿼리 성공, 해당 쿼리에서 insert된 행 갯수: " + rsSuccessCnts[i] );
      }
      returnValue ="false";     
  } finally { PoolManager.close( pstmt, conn);}


출처 : http://neouser.tistory.com/54