1 61 62 package org.apache.commons.dbutils.handlers; 63 64 import java.sql.ResultSet ; 65 import java.sql.SQLException ; 66 67 import org.apache.commons.dbutils.ResultSetHandler; 68 69 77 public class ScalarHandler implements ResultSetHandler { 78 79 82 private int columnIndex = 1; 83 84 88 private String columnName = null; 89 90 94 public ScalarHandler() { 95 super(); 96 } 97 98 104 public ScalarHandler(int columnIndex) { 105 this.columnIndex = columnIndex; 106 } 107 108 114 public ScalarHandler(String columnName) { 115 this.columnName = columnName; 116 } 117 118 130 public Object handle(ResultSet rs) throws SQLException { 131 132 if (rs.next()) { 133 if (this.columnName == null) { 134 return rs.getObject(this.columnIndex); 135 } else { 136 return rs.getObject(this.columnName); 137 } 138 139 } else { 140 return null; 141 } 142 } 143 } 144 | Popular Tags |