KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > relique > jdbc > csv > CsvResultSet


1 /**
2     Copyright (C) 2002-2003 Together
3
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Lesser General Public
6     License as published by the Free Software Foundation; either
7     version 2.1 of the License, or (at your option) any later version.
8
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12     Lesser General Public License for more details.
13
14     You should have received a copy of the GNU Lesser General Public
15     License along with this library; if not, write to the Free Software
16     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18 */

19
20 package org.relique.jdbc.csv;
21
22 import java.io.ByteArrayInputStream JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import java.io.Reader JavaDoc;
26 import java.io.StringReader JavaDoc;
27 import java.math.BigDecimal JavaDoc;
28 import java.net.URL JavaDoc;
29 import java.sql.*;
30 import java.util.Calendar JavaDoc;
31 import java.util.Map JavaDoc;
32
33 /**
34  * This class implements the ResultSet interface for the CsvJdbc driver.
35  *
36  * @author Zoran Milakovic
37  */

38 public class CsvResultSet implements ResultSet {
39
40     /** Metadata for this ResultSet */
41     protected ResultSetMetaData resultSetMetaData;
42
43     /** Statement that produced this ResultSet */
44     protected Statement statement;
45
46     /** Helper class that performs the actual file reads */
47     protected CsvReader reader;
48
49     /** Table referenced by the Statement */
50     protected String JavaDoc tableName;
51
52     /** Array of available columns for referenced table */
53     protected String JavaDoc[] columnNames;
54
55     protected Map JavaDoc columnTypes;
56     protected String JavaDoc[] whereColumnNames;
57
58     protected String JavaDoc[] whereColumnValues;
59
60
61     /** Last column name index read */
62     protected int lastIndexRead = -1;
63
64     /** InputStream to keep track of */
65     protected InputStream JavaDoc is;
66
67     /**
68      * Constructor for the CsvResultSet object
69      *
70      * @param statement Statement that produced this ResultSet
71      * @param reader Helper class that performs the actual file reads
72      * @param tableName Table referenced by the Statement
73      * @param columnNames Array of available columns for referenced table
74      */

75 // protected CsvResultSet(Statement statement, CsvReader reader,
76
// String tableName, String[] columnNames, String[] columnTypes) {
77
// this.statement = statement;
78
// this.reader = reader;
79
// this.tableName = tableName;
80
// this.columnNames = columnNames;
81
// this.columnTypes = columnTypes;
82
// if(columnNames[0].equals("*")) {
83
// this.columnNames = reader.getColumnNames();
84
// }
85
// }
86

87     /**
88      * Constructor for the CsvResultSet object
89      *
90      * @param statement Statement that produced this ResultSet
91      * @param reader Helper class that performs the actual file reads
92      * @param tableName Table referenced by the Statement
93      * @param columnNames Array of available columns for referenced table
94      */

95     protected CsvResultSet(Statement statement,
96                            CsvReader reader,
97                            String JavaDoc tableName,
98                            String JavaDoc[] columnNames,
99                            String JavaDoc[] columnWhereNames,
100                            String JavaDoc[] columnWhereValues,
101                            Map JavaDoc columnTypes) {
102         this.statement = statement;
103         this.reader = reader;
104         this.tableName = tableName;
105         this.columnNames = columnNames;
106         this.whereColumnNames = columnWhereNames;
107         this.whereColumnValues = columnWhereValues;
108         this.columnTypes = columnTypes;
109         if(columnNames[0].equals("*")) {
110             this.columnNames = reader.getColumnNames();
111         }
112     }
113
114     /**
115      * Moves the cursor down one row from its current position.
116      * A <code>ResultSet</code> cursor is initially positioned
117      * before the first row; the first call to the method
118      * <code>next</code> makes the first row the current row; the
119      * second call makes the second row the current row, and so on.
120      *
121      * <P>If an input stream is open for the current row, a call
122      * to the method <code>next</code> will
123      * implicitly close it. A <code>ResultSet</code> object's
124      * warning chain is cleared when a new row is read.
125      *
126      * @return <code>true</code> if the new current row is valid;
127      * <code>false</code> if there are no more rows
128      * @exception SQLException if a database access error occurs
129      */

130     public boolean next() throws SQLException {
131      mainLoop:
132      while(reader.next()) {
133         boolean isRow = true;
134         out:
135         for (int i = 0; i < this.whereColumnNames.length; i++) {
136 //csv driver make difference between null value and empty string ""
137
// if (whereColumnValues[i] == null || whereColumnValues[i].equals("null"))
138
// whereColumnValues[i] = "";
139
if ( !( Utils.compareValues( reader.getColumn(this.whereColumnNames[i]), this.whereColumnValues[i]) ) ) {
140             isRow = false;
141             break out;
142           }
143
144 // if (! (reader.getColumn(this.whereColumnNames[i]).equals(this.whereColumnValues[i]))) {
145
// isRow = false;
146
// break out;
147
// }
148
}
149         if (isRow == true)
150           return true;
151       }
152       return false;
153     }
154
155     /**
156      * Releases this <code>ResultSet</code> object's database and
157      * JDBC resources immediately instead of waiting for
158      * this to happen when it is automatically closed.
159      *
160      * <P><B>Note:</B> A <code>ResultSet</code> object
161      * is automatically closed by the
162      * <code>Statement</code> object that generated it when
163      * that <code>Statement</code> object is closed,
164      * re-executed, or is used to retrieve the next result from a
165      * sequence of multiple results. A <code>ResultSet</code> object
166      * is also automatically closed when it is garbage collected.
167      *
168      * @exception SQLException if a database access error occurs
169      */

170     public void close() throws SQLException {
171         reader.close();
172     }
173
174     /**
175      * Reports whether
176      * the last column read had a value of SQL <code>NULL</code>.
177      * Note that you must first call one of the getter methods
178      * on a column to try to read its value and then call
179      * the method <code>wasNull</code> to see if the value read was
180      * SQL <code>NULL</code>.
181      *
182      * @return <code>true</code> if the last column value read was SQL
183      * <code>NULL</code> and <code>false</code> otherwise
184      * @exception SQLException if a database access error occurs
185      */

186     public boolean wasNull() throws SQLException {
187         if(lastIndexRead >= 0) {
188             return getString(lastIndexRead) == null;
189         } else {
190             throw new SQLException("No previous getter method called");
191         }
192     }
193
194     //======================================================================
195
// Methods for accessing results by column index
196
//======================================================================
197

198     /**
199      * Retrieves the value of the designated column in the current row
200      * of this <code>ResultSet</code> object as
201      * a <code>String</code> in the Java programming language.
202      *
203      * @param columnIndex the first column is 1, the second is 2, ...
204      * @return the column value; if the value is SQL <code>NULL</code>, the
205      * value returned is <code>null</code>
206      * @exception SQLException if a database access error occurs
207      */

208     public String JavaDoc getString(int columnIndex) throws SQLException {
209         // perform pre-accessor method processing
210
preAccessor(columnIndex);
211         // use CsvReader.getColumn(String) to retrieve the column
212
if (columnIndex < 1 || columnIndex > columnNames.length) {
213             throw new SQLException("Column not found: invalid index: "+columnIndex);
214         }
215         String JavaDoc retValue = reader.getColumn(columnNames[columnIndex-1]);
216         //replace spec. characters
217
// retValue = this.formatString(retValue);
218
return retValue;
219     }
220
221     /**
222      * Retrieves the value of the designated column in the current row
223      * of this <code>ResultSet</code> object as
224      * a <code>boolean</code> in the Java programming language.
225      *
226      * @param columnIndex the first column is 1, the second is 2, ...
227      * @return the column value; if the value is SQL <code>NULL</code>, the
228      * value returned is <code>false</code>
229      * @exception SQLException if a database access error occurs
230      */

231     public boolean getBoolean(int columnIndex) throws SQLException {
232         String JavaDoc str = getString(columnIndex);
233         return (str == null) ? false : Boolean.valueOf(str).booleanValue();
234     }
235
236     /**
237      * Retrieves the value of the designated column in the current row
238      * of this <code>ResultSet</code> object as
239      * a <code>byte</code> in the Java programming language.
240      *
241      * @param columnIndex the first column is 1, the second is 2, ...
242      * @return the column value; if the value is SQL <code>NULL</code>, the
243      * value returned is <code>0</code>
244      * @exception SQLException if a database access error occurs
245      */

246     public byte getByte(int columnIndex) throws SQLException {
247         String JavaDoc str = getString(columnIndex);
248         return (str == null) ? 0 : Byte.parseByte(str);
249     }
250
251     /**
252      * Retrieves the value of the designated column in the current row
253      * of this <code>ResultSet</code> object as
254      * a <code>short</code> in the Java programming language.
255      *
256      * @param columnIndex the first column is 1, the second is 2, ...
257      * @return the column value; if the value is SQL <code>NULL</code>, the
258      * value returned is <code>0</code>
259      * @exception SQLException if a database access error occurs
260      */

261     public short getShort(int columnIndex) throws SQLException {
262         String JavaDoc str = getString(columnIndex);
263         return (str == null) ? 0 : Short.parseShort(str);
264     }
265
266     /**
267      * Gets the value of the designated column in the current row
268      * of this <code>ResultSet</code> object as
269      * an <code>int</code> in the Java programming language.
270      *
271      * @param columnIndex the first column is 1, the second is 2, ...
272      * @return the column value; if the value is SQL <code>NULL</code>, the
273      * value returned is <code>0</code>
274      * @exception SQLException if a database access error occurs
275      */

276     public int getInt(int columnIndex) throws SQLException {
277         String JavaDoc str = getString(columnIndex);
278         return (str == null) ? 0 : Integer.parseInt(str);
279     }
280
281     /**
282      * Retrieves the value of the designated column in the current row
283      * of this <code>ResultSet</code> object as
284      * a <code>long</code> in the Java programming language.
285      *
286      * @param columnIndex the first column is 1, the second is 2, ...
287      * @return the column value; if the value is SQL <code>NULL</code>, the
288      * value returned is <code>0</code>
289      * @exception SQLException if a database access error occurs
290      */

291     public long getLong(int columnIndex) throws SQLException {
292         String JavaDoc str = getString(columnIndex);
293         return (str == null) ? 0L : Long.parseLong(str);
294     }
295
296     /**
297      * Gets the value of the designated column in the current row
298      * of this <code>ResultSet</code> object as
299      * a <code>float</code> in the Java programming language.
300      *
301      * @param columnIndex the first column is 1, the second is 2, ...
302      * @return the column value; if the value is SQL <code>NULL</code>, the
303      * value returned is <code>0</code>
304      * @exception SQLException if a database access error occurs
305      */

306     public float getFloat(int columnIndex) throws SQLException {
307         String JavaDoc str = getString(columnIndex);
308         return (str == null) ? 0F : Float.parseFloat(str);
309     }
310
311     /**
312      * Retrieves the value of the designated column in the current row
313      * of this <code>ResultSet</code> object as
314      * a <code>double</code> in the Java programming language.
315      *
316      * @param columnIndex the first column is 1, the second is 2, ...
317      * @return the column value; if the value is SQL <code>NULL</code>, the
318      * value returned is <code>0</code>
319      * @exception SQLException if a database access error occurs
320      */

321     public double getDouble(int columnIndex) throws SQLException {
322         String JavaDoc str = getString(columnIndex);
323         return (str == null) ? 0D : Double.parseDouble(str);
324     }
325
326     /**
327      * Retrieves the value of the designated column in the current row
328      * of this <code>ResultSet</code> object as
329      * a <code>java.sql.BigDecimal</code> in the Java programming language.
330      *
331      * @param columnIndex the first column is 1, the second is 2, ...
332      * @param scale the number of digits to the right of the decimal point
333      * @return the column value; if the value is SQL <code>NULL</code>, the
334      * value returned is <code>null</code>
335      * @exception SQLException if a database access error occurs
336      * @deprecated
337      */

338     public BigDecimal JavaDoc getBigDecimal(int columnIndex, int scale)
339             throws SQLException {
340         // let getBigDecimal(int) handle this for now
341
return getBigDecimal(columnIndex);
342     }
343
344     /**
345      * Retrieves the value of the designated column in the current row
346      * of this <code>ResultSet</code> object as
347      * a <code>byte</code> array in the Java programming language.
348      * The bytes represent the raw values returned by the driver.
349      *
350      * @param columnIndex the first column is 1, the second is 2, ...
351      * @return the column value; if the value is SQL <code>NULL</code>, the
352      * value returned is <code>null</code>
353      * @exception SQLException if a database access error occurs
354      */

355     public byte[] getBytes(int columnIndex) throws SQLException {
356         String JavaDoc str = getString(columnIndex);
357         return (str == null || str.equals("")) ? null : Utils.hexStringToBytes(str);
358     }
359
360     /**
361      * Retrieves the value of the designated column in the current row
362      * of this <code>ResultSet</code> object as
363      * a <code>java.sql.Date</code> object in the Java programming language.
364      *
365      * @param columnIndex the first column is 1, the second is 2, ...
366      * @return the column value; if the value is SQL <code>NULL</code>, the
367      * value returned is <code>null</code>
368      * @exception SQLException if a database access error occurs
369      */

370     public Date getDate(int columnIndex) throws SQLException {
371         String JavaDoc str = getString(columnIndex);
372         return (str == null) ? null : Date.valueOf(str);
373     }
374
375     /**
376      * Retrieves the value of the designated column in the current row
377      * of this <code>ResultSet</code> object as
378      * a <code>java.sql.Time</code> object in the Java programming language.
379      *
380      * @param columnIndex the first column is 1, the second is 2, ...
381      * @return the column value; if the value is SQL <code>NULL</code>, the
382      * value returned is <code>null</code>
383      * @exception SQLException if a database access error occurs
384      */

385     public Time getTime(int columnIndex) throws SQLException {
386         String JavaDoc str = getString(columnIndex);
387         return (str == null) ? null : Time.valueOf(str);
388     }
389
390     /**
391      * Retrieves the value of the designated column in the current row
392      * of this <code>ResultSet</code> object as a
393      * <code>java.sql.Timestamp</code> object in the Java programming language.
394      *
395      * @param columnIndex the first column is 1, the second is 2, ...
396      * @return the column value; if the value is SQL <code>NULL</code>, the
397      * value returned is <code>null</code>
398      * @exception SQLException if a database access error occurs
399      */

400     public Timestamp getTimestamp(int columnIndex) throws SQLException {
401         String JavaDoc str = getString(columnIndex);
402         return (str == null) ? null : Timestamp.valueOf(str);
403     }
404
405     /**
406      * Retrieves the value of the designated column in the current row
407      * of this <code>ResultSet</code> object as a stream of ASCII characters.
408      * The value can then be read in chunks from the stream. This method is
409      * particularly suitable for retrieving large <char>LONGVARCHAR</char>
410      * values. The JDBC driver will do any necessary conversion from the
411      * database format into ASCII.
412      *
413      * <P><B>Note:</B> All the data in the returned stream must be
414      * read prior to getting the value of any other column. The next
415      * call to a getter method implicitly closes the stream. Also, a
416      * stream may return <code>0</code> when the method
417      * <code>InputStream.available</code>
418      * is called whether there is data available or not.
419      *
420      * @param columnIndex the first column is 1, the second is 2, ...
421      * @return a Java input stream that delivers the database column value
422      * as a stream of one-byte ASCII characters;
423      * if the value is SQL <code>NULL</code>, the
424      * value returned is <code>null</code>
425      * @exception SQLException if a database access error occurs
426      */

427     public InputStream JavaDoc getAsciiStream(int columnIndex) throws SQLException {
428         String JavaDoc str = getString(columnIndex);
429         is = new ByteArrayInputStream JavaDoc(str.getBytes());
430         return (str == null) ? null : is;
431     }
432
433     /**
434      * Retrieves the value of the designated column in the current row
435      * of this <code>ResultSet</code> object as
436      * as a stream of two-byte Unicode characters. The first byte is
437      * the high byte; the second byte is the low byte.
438      *
439      * The value can then be read in chunks from the
440      * stream. This method is particularly
441      * suitable for retrieving large <code>LONGVARCHAR</code>values. The
442      * JDBC driver will do any necessary conversion from the database
443      * format into Unicode.
444      *
445      * <P><B>Note:</B> All the data in the returned stream must be
446      * read prior to getting the value of any other column. The next
447      * call to a getter method implicitly closes the stream.
448      * Also, a stream may return <code>0</code> when the method
449      * <code>InputStream.available</code>
450      * is called, whether there is data available or not.
451      *
452      * @param columnIndex the first column is 1, the second is 2, ...
453      * @return a Java input stream that delivers the database column value
454      * as a stream of two-byte Unicode characters;
455      * if the value is SQL <code>NULL</code>, the value returned is
456      * <code>null</code>
457      *
458      * @exception SQLException if a database access error occurs
459      * @deprecated use <code>getCharacterStream</code> in place of
460      * <code>getUnicodeStream</code>
461      */

462     public InputStream JavaDoc getUnicodeStream(int columnIndex) throws SQLException {
463         // delegate to getAsciiStream(int)
464
return getAsciiStream(columnIndex);
465     }
466
467     /**
468      * Retrieves the value of the designated column in the current row
469      * of this <code>ResultSet</code> object as a binary stream of
470      * uninterpreted bytes. The value can then be read in chunks from the
471      * stream. This method is particularly
472      * suitable for retrieving large <code>LONGVARBINARY</code> values.
473      *
474      * <P><B>Note:</B> All the data in the returned stream must be
475      * read prior to getting the value of any other column. The next
476      * call to a getter method implicitly closes the stream. Also, a
477      * stream may return <code>0</code> when the method
478      * <code>InputStream.available</code>
479      * is called whether there is data available or not.
480      *
481      * @param columnIndex the first column is 1, the second is 2, ...
482      * @return a Java input stream that delivers the database column value
483      * as a stream of uninterpreted bytes;
484      * if the value is SQL <code>NULL</code>, the value returned is
485      * <code>null</code>
486      * @exception SQLException if a database access error occurs
487      */

488     public InputStream JavaDoc getBinaryStream(int columnIndex) throws SQLException {
489         // delegate to getAsciiStream(int)
490
return getAsciiStream(columnIndex);
491     }
492
493     //======================================================================
494
// Methods for accessing results by column name
495
//======================================================================
496

497     /**
498      * Retrieves the value of the designated column in the current row
499      * of this <code>ResultSet</code> object as
500      * a <code>String</code> in the Java programming language.
501      *
502      * @param columnName the SQL name of the column
503      * @return the column value; if the value is SQL <code>NULL</code>, the
504      * value returned is <code>null</code>
505      * @exception SQLException if a database access error occurs
506      */

507     public String JavaDoc getString(String JavaDoc columnName) throws SQLException {
508         // perform pre-accessor method processing
509
preAccessor(columnName);
510         // use CsvReader.getColumn(String) to retrieve the column
511
String JavaDoc retValue = reader.getColumn(columnName);
512         //replace spec. characters
513
// retValue = this.formatString(retValue);
514
return retValue;
515     }
516
517     /**
518      * Retrieves the value of the designated column in the current row
519      * of this <code>ResultSet</code> object as
520      * a <code>boolean</code> in the Java programming language.
521      *
522      * @param columnName the SQL name of the column
523      * @return the column value; if the value is SQL <code>NULL</code>, the
524      * value returned is <code>false</code>
525      * @exception SQLException if a database access error occurs
526      */

527     public boolean getBoolean(String JavaDoc columnName) throws SQLException {
528         String JavaDoc str = getString(columnName);
529         return (str == null) ? false : Boolean.valueOf(str).booleanValue();
530     }
531
532     /**
533      * Retrieves the value of the designated column in the current row
534      * of this <code>ResultSet</code> object as
535      * a <code>byte</code> in the Java programming language.
536      *
537      * @param columnName the SQL name of the column
538      * @return the column value; if the value is SQL <code>NULL</code>, the
539      * value returned is <code>0</code>
540      * @exception SQLException if a database access error occurs
541      */

542     public byte getByte(String JavaDoc columnName) throws SQLException {
543         String JavaDoc str = getString(columnName);
544         return (str == null) ? 0 : Byte.parseByte(str);
545     }
546
547     /**
548      * Retrieves the value of the designated column in the current row
549      * of this <code>ResultSet</code> object as
550      * a <code>short</code> in the Java programming language.
551      *
552      * @param columnName the SQL name of the column
553      * @return the column value; if the value is SQL <code>NULL</code>, the
554      * value returned is <code>0</code>
555      * @exception SQLException if a database access error occurs
556      */

557     public short getShort(String JavaDoc columnName) throws SQLException {
558         String JavaDoc str = getString(columnName);
559         return (str == null) ? 0 : Short.parseShort(str);
560     }
561
562     /**
563      * Gets the value of the designated column in the current row
564      * of this <code>ResultSet</code> object as
565      * an <code>int</code> in the Java programming language.
566      *
567      * @param columnName the SQL name of the column
568      * @return the column value; if the value is SQL <code>NULL</code>, the
569      * value returned is <code>0</code>
570      * @exception SQLException if a database access error occurs
571      */

572     public int getInt(String JavaDoc columnName) throws SQLException {
573         String JavaDoc str = getString(columnName);
574         return (str == null) ? 0 : Integer.parseInt(str);
575     }
576
577     /**
578      * Retrieves the value of the designated column in the current row
579      * of this <code>ResultSet</code> object as
580      * a <code>long</code> in the Java programming language.
581      *
582      * @param columnName the SQL name of the column
583      * @return the column value; if the value is SQL <code>NULL</code>, the
584      * value returned is <code>0</code>
585      * @exception SQLException if a database access error occurs
586      */

587     public long getLong(String JavaDoc columnName) throws SQLException {
588         String JavaDoc str = getString(columnName);
589         return (str == null) ? 0L : Long.parseLong(str);
590     }
591
592     /**
593      * Gets the value of the designated column in the current row
594      * of this <code>ResultSet</code> object as
595      * a <code>float</code> in the Java programming language.
596      *
597      * @param columnName the SQL name of the column
598      * @return the column value; if the value is SQL <code>NULL</code>, the
599      * value returned is <code>0</code>
600      * @exception SQLException if a database access error occurs
601      */

602     public float getFloat(String JavaDoc columnName) throws SQLException {
603         String JavaDoc str = getString(columnName);
604         return (str == null) ? 0F : Float.parseFloat(str);
605     }
606
607     /**
608      * Retrieves the value of the designated column in the current row
609      * of this <code>ResultSet</code> object as
610      * a <code>double</code> in the Java programming language.
611      *
612      * @param columnName the SQL name of the column
613      * @return the column value; if the value is SQL <code>NULL</code>, the
614      * value returned is <code>0</code>
615      * @exception SQLException if a database access error occurs
616      */

617     public double getDouble(String JavaDoc columnName) throws SQLException {
618         String JavaDoc str = getString(columnName);
619         return (str == null) ? 0D : Double.parseDouble(str);
620     }
621
622     /**
623      * Retrieves the value of the designated column in the current row
624      * of this <code>ResultSet</code> object as
625      * a <code>java.math.BigDecimal</code> in the Java programming language.
626      *
627      * @param columnName the SQL name of the column
628      * @param scale the number of digits to the right of the decimal point
629      * @return the column value; if the value is SQL <code>NULL</code>, the
630      * value returned is <code>null</code>
631      * @exception SQLException if a database access error occurs
632      * @deprecated
633      */

634     public BigDecimal JavaDoc getBigDecimal(String JavaDoc columnName, int scale)
635             throws SQLException {
636         // let getBigDecimal(String) handle this for now
637
return getBigDecimal(columnName);
638     }
639
640     /**
641      * Retrieves the value of the designated column in the current row
642      * of this <code>ResultSet</code> object as
643      * a <code>byte</code> array in the Java programming language.
644      * The bytes represent the raw values returned by the driver.
645      *
646      * @param columnName the SQL name of the column
647      * @return the column value; if the value is SQL <code>NULL</code>, the
648      * value returned is <code>null</code>
649      * @exception SQLException if a database access error occurs
650      */

651     public byte[] getBytes(String JavaDoc columnName) throws SQLException {
652         String JavaDoc str = getString(columnName);
653         return (str == null) ? null : Utils.hexStringToBytes(str);
654     }
655
656     /**
657      * Retrieves the value of the designated column in the current row
658      * of this <code>ResultSet</code> object as
659      * a <code>java.sql.Date</code> object in the Java programming language.
660      *
661      * @param columnName the SQL name of the column
662      * @return the column value; if the value is SQL <code>NULL</code>, the
663      * value returned is <code>null</code>
664      * @exception SQLException if a database access error occurs
665      */

666     public Date getDate(String JavaDoc columnName) throws SQLException {
667         String JavaDoc str = getString(columnName);
668         return (str == null) ? null : Date.valueOf(str);
669     }
670
671     /**
672      * Retrieves the value of the designated column in the current row
673      * of this <code>ResultSet</code> object as
674      * a <code>java.sql.Time</code> object in the Java programming language.
675      *
676      * @param columnName the SQL name of the column
677      * @return the column value;
678      * if the value is SQL <code>NULL</code>,
679      * the value returned is <code>null</code>
680      * @exception SQLException if a database access error occurs
681      */

682     public Time getTime(String JavaDoc columnName) throws SQLException {
683         String JavaDoc str = getString(columnName);
684         return (str == null) ? null : Time.valueOf(str);
685     }
686
687     /**
688      * Retrieves the value of the designated column in the current row
689      * of this <code>ResultSet</code> object as
690      * a <code>java.sql.Timestamp</code> object.
691      *
692      * @param columnName the SQL name of the column
693      * @return the column value; if the value is SQL <code>NULL</code>, the
694      * value returned is <code>null</code>
695      * @exception SQLException if a database access error occurs
696      */

697     public Timestamp getTimestamp(String JavaDoc columnName) throws SQLException {
698         String JavaDoc str = getString(columnName);
699         return (str == null) ? null : Timestamp.valueOf(str);
700     }
701
702     /**
703      * Retrieves the value of the designated column in the current row
704      * of this <code>ResultSet</code> object as a stream of
705      * ASCII characters. The value can then be read in chunks from the
706      * stream. This method is particularly
707      * suitable for retrieving large <code>LONGVARCHAR</code> values.
708      * The JDBC driver will
709      * do any necessary conversion from the database format into ASCII.
710      *
711      * <P><B>Note:</B> All the data in the returned stream must be
712      * read prior to getting the value of any other column. The next
713      * call to a getter method implicitly closes the stream. Also, a
714      * stream may return <code>0</code> when the method <code>available</code>
715      * is called whether there is data available or not.
716      *
717      * @param columnName the SQL name of the column
718      * @return a Java input stream that delivers the database column value
719      * as a stream of one-byte ASCII characters.
720      * If the value is SQL <code>NULL</code>,
721      * the value returned is <code>null</code>.
722      * @exception SQLException if a database access error occurs
723      */

724     public InputStream JavaDoc getAsciiStream(String JavaDoc columnName) throws SQLException {
725         String JavaDoc str = getString(columnName);
726         is = new ByteArrayInputStream JavaDoc(str.getBytes());
727         return (str == null) ? null : is;
728     }
729
730     /**
731      * Retrieves the value of the designated column in the current row
732      * of this <code>ResultSet</code> object as a stream of two-byte
733      * Unicode characters. The first byte is the high byte; the second
734      * byte is the low byte.
735      *
736      * The value can then be read in chunks from the
737      * stream. This method is particularly
738      * suitable for retrieving large <code>LONGVARCHAR</code> values.
739      * The JDBC technology-enabled driver will
740      * do any necessary conversion from the database format into Unicode.
741      *
742      * <P><B>Note:</B> All the data in the returned stream must be
743      * read prior to getting the value of any other column. The next
744      * call to a getter method implicitly closes the stream.
745      * Also, a stream may return <code>0</code> when the method
746      * <code>InputStream.available</code> is called, whether there
747      * is data available or not.
748      *
749      * @param columnName the SQL name of the column
750      * @return a Java input stream that delivers the database column value
751      * as a stream of two-byte Unicode characters.
752      * If the value is SQL <code>NULL</code>, the value returned
753      * is <code>null</code>.
754      * @exception SQLException if a database access error occurs
755      * @deprecated use <code>getCharacterStream</code> instead
756      */

757     public InputStream JavaDoc getUnicodeStream(String JavaDoc columnName) throws SQLException {
758         // delegate to getAsciiStream(String)
759
return getAsciiStream(columnName);
760     }
761
762     /**
763      * Retrieves the value of the designated column in the current row
764      * of this <code>ResultSet</code> object as a stream of uninterpreted
765      * <code>byte</code>s.
766      * The value can then be read in chunks from the
767      * stream. This method is particularly
768      * suitable for retrieving large <code>LONGVARBINARY</code>
769      * values.
770      *
771      * <P><B>Note:</B> All the data in the returned stream must be
772      * read prior to getting the value of any other column. The next
773      * call to a getter method implicitly closes the stream. Also, a
774      * stream may return <code>0</code> when the method <code>available</code>
775      * is called whether there is data available or not.
776      *
777      * @param columnName the SQL name of the column
778      * @return a Java input stream that delivers the database column value
779      * as a stream of uninterpreted bytes;
780      * if the value is SQL <code>NULL</code>, the result is <code>null</code>
781      * @exception SQLException if a database access error occurs
782      */

783     public InputStream JavaDoc getBinaryStream(String JavaDoc columnName) throws SQLException {
784         // delegate to getAsciiStream(String)
785
return getAsciiStream(columnName);
786     }
787
788     //=====================================================================
789
// Advanced features:
790
//=====================================================================
791

792     /**
793      * Retrieves the first warning reported by calls on this
794      * <code>ResultSet</code> object.
795      * Subsequent warnings on this <code>ResultSet</code> object
796      * will be chained to the <code>SQLWarning</code> object that
797      * this method returns.
798      *
799      * <P>The warning chain is automatically cleared each time a new
800      * row is read. This method may not be called on a <code>ResultSet</code>
801      * object that has been closed; doing so will cause an
802      * <code>SQLException</code> to be thrown.
803      * <P>
804      * <B>Note:</B> This warning chain only covers warnings caused
805      * by <code>ResultSet</code> methods. Any warning caused by
806      * <code>Statement</code> methods
807      * (such as reading OUT parameters) will be chained on the
808      * <code>Statement</code> object.
809      *
810      * @return the first <code>SQLWarning</code> object reported or
811      * <code>null</code> if there are none
812      * @exception SQLException if a database access error occurs or this method
813      * is called on a closed result set
814      */

815     public SQLWarning getWarnings() throws SQLException {
816         throw new UnsupportedOperationException JavaDoc(
817                 "ResultSet.getWarnings() unsupported");
818     }
819
820     /**
821      * Clears all warnings reported on this <code>ResultSet</code> object.
822      * After this method is called, the method <code>getWarnings</code>
823      * returns <code>null</code> until a new warning is
824      * reported for this <code>ResultSet</code> object.
825      *
826      * @exception SQLException if a database access error occurs
827      */

828     public void clearWarnings() throws SQLException {
829         throw new UnsupportedOperationException JavaDoc(
830                 "ResultSet.clearWarnings() unsupported");
831     }
832
833     /**
834      * Retrieves the name of the SQL cursor used by this <code>ResultSet</code>
835      * object.
836      *
837      * <P>In SQL, a result table is retrieved through a cursor that is
838      * named. The current row of a result set can be updated or deleted
839      * using a positioned update/delete statement that references the
840      * cursor name. To insure that the cursor has the proper isolation
841      * level to support update, the cursor's <code>SELECT</code> statement
842      * should be of the form <code>SELECT FOR UPDATE</code>. If
843      * <code>FOR UPDATE</code> is omitted, the positioned updates may fail.
844      *
845      * <P>The JDBC API supports this SQL feature by providing the name of the
846      * SQL cursor used by a <code>ResultSet</code> object.
847      * The current row of a <code>ResultSet</code> object
848      * is also the current row of this SQL cursor.
849      *
850      * <P><B>Note:</B> If positioned update is not supported, a
851      * <code>SQLException</code> is thrown.
852      *
853      * @return the SQL name for this <code>ResultSet</code> object's cursor
854      * @exception SQLException if a database access error occurs
855      */

856     public String JavaDoc getCursorName() throws SQLException {
857         throw new UnsupportedOperationException JavaDoc(
858                 "ResultSet.getCursorName() unsupported");
859     }
860
861     /**
862      * Retrieves the number, types and properties of
863      * this <code>ResultSet</code> object's columns.
864      *
865      * @return the description of this <code>ResultSet</code> object's columns
866      * @exception SQLException if a database access error occurs
867      */

868     public ResultSetMetaData getMetaData() throws SQLException {
869         if (resultSetMetaData == null) {
870             resultSetMetaData = new CsvResultSetMetaData(tableName,columnNames,columnTypes);
871         }
872         return resultSetMetaData;
873     }
874
875     /**
876      * <p>Gets the value of the designated column in the current row
877      * of this <code>ResultSet</code> object as
878      * an <code>Object</code> in the Java programming language.
879      *
880      * <p>This method will return the value of the given column as a
881      * Java object. The type of the Java object will be the default
882      * Java object type corresponding to the column's SQL type,
883      * following the mapping for built-in types specified in the JDBC
884      * specification. If the value is an SQL <code>NULL</code>,
885      * the driver returns a Java <code>null</code>.
886      *
887      * <p>This method may also be used to read datatabase-specific
888      * abstract data types.
889      *
890      * In the JDBC 2.0 API, the behavior of method
891      * <code>getObject</code> is extended to materialize
892      * data of SQL user-defined types. When a column contains
893      * a structured or distinct value, the behavior of this method is as
894      * if it were a call to: <code>getObject(columnIndex,
895      * this.getStatement().getConnection().getTypeMap())</code>.
896      *
897      * @param columnIndex the first column is 1, the second is 2, ...
898      * @return a <code>java.lang.Object</code> holding the column value
899      * @exception SQLException if a database access error occurs
900      */

901     public Object JavaDoc getObject(int columnIndex) throws SQLException {
902 // throw new UnsupportedOperationException(
903
// "ResultSet.getObject(int) unsupported");
904
return getString(columnIndex);
905 }
906     /**
907      * <p>Gets the value of the designated column in the current row
908      * of this <code>ResultSet</code> object as
909      * an <code>Object</code> in the Java programming language.
910      *