1 16 17 package org.springframework.jdbc.core; 18 19 import java.sql.ResultSet ; 20 import java.sql.ResultSetMetaData ; 21 import java.sql.SQLException ; 22 23 43 public class RowCountCallbackHandler implements RowCallbackHandler { 44 45 46 private int rowCount; 47 48 49 private int columnCount; 50 51 55 private int[] columnTypes; 56 57 60 private String [] columnNames; 61 62 63 70 public final void processRow(ResultSet rs) throws SQLException { 71 if (this.rowCount == 0) { 72 ResultSetMetaData rsmd = rs.getMetaData(); 73 this.columnCount = rsmd.getColumnCount(); 74 this.columnTypes = new int[this.columnCount]; 75 this.columnNames = new String [this.columnCount]; 76 for (int i = 0; i < this.columnCount; i++) { 77 this.columnTypes[i] = rsmd.getColumnType(i + 1); 78 this.columnNames[i] = rsmd.getColumnName(i + 1); 79 } 80 } 82 processRow(rs, this.rowCount++); 83 } 84 85 92 protected void processRow(ResultSet rs, int rowNum) throws SQLException { 93 } 94 95 96 102 public final int[] getColumnTypes() { 103 return columnTypes; 104 } 105 106 112 public final String [] getColumnNames() { 113 return columnNames; 114 } 115 116 121 public final int getRowCount() { 122 return rowCount; 123 } 124 125 131 public final int getColumnCount() { 132 return columnCount; 133 } 134 135 } 136 | Popular Tags |