1 28 package com.caucho.db.jdbc; 29 30 import com.caucho.db.sql.SelectResult; 31 32 import java.math.BigDecimal ; 33 import java.sql.Blob ; 34 import java.sql.Clob ; 35 import java.sql.SQLException ; 36 import java.sql.Time ; 37 import java.sql.Timestamp ; 38 39 42 public class ResultSetImpl extends AbstractResultSet { 43 private StatementImpl _stmt; 44 private SelectResult _rs; 45 private int _rowNumber; 46 47 ResultSetImpl(StatementImpl stmt, SelectResult rs) 48 { 49 _stmt = stmt; 50 _rs = rs; 51 } 52 53 public int getRow() 54 throws SQLException 55 { 56 if (_rowNumber < 0) 57 throw new SQLException ("can't call getRow() after close()"); 58 59 return _rowNumber; 60 } 61 62 public boolean isBeforeFirst() 63 throws SQLException 64 { 65 return _rowNumber == 0; 66 } 67 68 public boolean isFirst() 69 throws SQLException 70 { 71 return _rowNumber == 1; 72 } 73 74 public java.sql.Statement getStatement() 75 throws SQLException 76 { 77 if (_rowNumber < 0) 78 throw new SQLException ("can't call getStatement() after close()"); 79 80 return _stmt; 81 } 82 83 public java.sql.ResultSetMetaData getMetaData() 84 throws SQLException 85 { 86 if (_rowNumber < 0) 87 throw new SQLException ("can't call getMetaData() after close()"); 88 89 return new ResultSetMetaDataImpl(_rs); 90 } 91 92 public boolean wasNull() 93 throws SQLException 94 { 95 return _rs.wasNull(); 96 } 97 98 101 public boolean next() 102 throws SQLException 103 { 104 if (_rs == null) 105 return false; 106 else if (_rs.next()) 107 return true; 108 else { 109 close(); 110 111 return false; 112 } 113 } 114 115 public int findColumn(String columnName) 116 throws SQLException 117 { 118 return _rs.findColumnIndex(columnName); 119 } 120 121 124 public boolean getBoolean(int columnIndex) 125 throws SQLException 126 { 127 String s = getString(columnIndex); 128 129 return s != null && ! s.equals("") && ! s.equals("0") && ! s.equals("n"); 130 } 131 132 135 public java.sql.Date getDate(int columnIndex) 136 throws SQLException 137 { 138 long date = _rs.getDate(columnIndex - 1); 139 140 if (wasNull()) 141 return null; 142 else 143 return new java.sql.Date (date); 144 } 145 146 149 public double getDouble(int columnIndex) 150 throws SQLException 151 { 152 return _rs.getDouble(columnIndex - 1); 153 } 154 155 158 public int getInt(int columnIndex) 159 throws SQLException 160 { 161 return _rs.getInt(columnIndex - 1); 162 } 163 164 167 public long getLong(int columnIndex) 168 throws SQLException 169 { 170 return _rs.getLong(columnIndex - 1); 171 } 172 173 176 public String getString(int columnIndex) 177 throws SQLException 178 { 179 return _rs.getString(columnIndex - 1); 180 } 181 182 185 public Time getTime(int columnIndex) 186 throws SQLException 187 { 188 long date = _rs.getDate(columnIndex - 1); 189 190 if (wasNull()) 191 return null; 192 else 193 return new java.sql.Time (date); 194 } 195 196 public Timestamp getTimestamp(int columnIndex) 197 throws SQLException 198 { 199 long date = _rs.getDate(columnIndex - 1); 200 201 if (wasNull()) 202 return null; 203 else 204 return new java.sql.Timestamp (date); 205 } 206 207 210 public BigDecimal getBigDecimal(int columnIndex) 211 throws SQLException 212 { 213 return new BigDecimal (_rs.getString(columnIndex - 1)); 214 } 215 216 219 public Blob getBlob(int columnIndex) 220 throws SQLException 221 { 222 return _rs.getBlob(columnIndex - 1); 223 } 224 225 228 public Clob getClob(int columnIndex) 229 throws SQLException 230 { 231 return _rs.getClob(columnIndex - 1); 232 } 233 234 public void close() 235 throws SQLException 236 { 237 SelectResult result = _rs; 238 _rs = null; 239 240 if (result != null) 241 result.close(); 242 } 243 } 244 | Popular Tags |