KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > internetcds > jdbc > tds > ResultSet_base


1 //
2
// Copyright 1998, 1999 CDS Networks, Inc., Medford Oregon
3
//
4
// All rights reserved.
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are met:
8
// 1. Redistributions of source code must retain the above copyright
9
// notice, this list of conditions and the following disclaimer.
10
// 2. Redistributions in binary form must reproduce the above copyright
11
// notice, this list of conditions and the following disclaimer in the
12
// documentation and/or other materials provided with the distribution.
13
// 3. All advertising materials mentioning features or use of this software
14
// must display the following acknowledgement:
15
// This product includes software developed by CDS Networks, Inc.
16
// 4. The name of CDS Networks, Inc. may not be used to endorse or promote
17
// products derived from this software without specific prior
18
// written permission.
19
//
20
// THIS SOFTWARE IS PROVIDED BY CDS NETWORKS, INC. ``AS IS'' AND
21
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
// ARE DISCLAIMED. IN NO EVENT SHALL CDS NETWORKS, INC. BE LIABLE
24
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30
// SUCH DAMAGE.
31
//
32

33
34 package com.internetcds.jdbc.tds;
35
36 import java.sql.*;
37 import java.math.BigDecimal JavaDoc;
38 import java.util.Vector JavaDoc;
39 // import java.util.Calendar;
40
import java.util.GregorianCalendar JavaDoc;
41 import java.util.Calendar JavaDoc;
42 import java.io.*;
43
44 /**
45  * <P>A ResultSet provides access to a table of data generated by
46  * executing a Statement. The table rows are retrieved in
47  * sequence. Within a row its column values can be accessed in any
48  * order.
49  *
50  * <P>A ResultSet maintains a cursor pointing to its current row of
51  * data. Initially the cursor is positioned before the first row.
52  * The 'next' method moves the cursor to the next row.
53  *
54  * <P>The getXXX methods retrieve column values for the current
55  * row. You can retrieve values either using the index number of the
56  * column, or by using the name of the column. In general using the
57  * column index will be more efficient. Columns are numbered from 1.
58  *
59  * <P>For maximum portability, ResultSet columns within each row should be
60  * read in left-to-right order and each column should be read only once.
61  *
62  * <P>For the getXXX methods, the JDBC driver attempts to convert the
63  * underlying data to the specified Java type and returns a suitable
64  * Java value. See the JDBC specification for allowable mappings
65  * from SQL types to Java types with the ResultSet.getXXX methods.
66  *
67  * <P>Column names used as input to getXXX methods are case
68  * insensitive. When performing a getXXX using a column name, if
69  * several columns have the same name, then the value of the first
70  * matching column will be returned. The column name option is
71  * designed to be used when column names are used in the SQL
72  * query. For columns that are NOT explicitly named in the query, it
73  * is best to use column numbers. If column names were used there is
74  * no way for the programmer to guarantee that they actually refer to
75  * the intended columns.
76  *
77  * <P>A ResultSet is automatically closed by the Statement that
78  * generated it when that Statement is closed, re-executed, or is used
79  * to retrieve the next result from a sequence of multiple results.
80  *
81  * <P>The number, types and properties of a ResultSet's columns are
82  * provided by the ResulSetMetaData object returned by the getMetaData
83  * method.
84  *
85  * @author Craig Spannring
86  * @author The FreeTDS project
87  * @version $Id: ResultSet_base.java,v 1.1 2006/06/23 10:39:30 sinisa Exp $
88  *
89  * @see Statement#executeQuery
90  * @see Statement#getResultSet
91  * @see ResultSetMetaData
92  @ @see Tds#getRow
93  */

94
95 public class ResultSet_base
96 {
97    public static final String JavaDoc cvsVersion = "$Id: ResultSet_base.java,v 1.1 2006/06/23 10:39:30 sinisa Exp $";
98
99
100    Tds tds = null;
101    Statement stmt = null;
102    Columns columnsInfo = null;
103    ResultSetMetaData metaData = null;
104    PacketRowResult currentRow = null;
105    boolean lastGetWasNull = false;
106
107    boolean hitEndOfData = false;
108    boolean isClosed = false;
109
110    private SQLWarningChain warningChain = null; // The warnings chain.
111

112    public ResultSet_base(Tds tds_, Statement stmt_, Columns columns_)
113    {
114       tds = tds_;
115       stmt = stmt_;
116       columnsInfo = columns_;
117
118       hitEndOfData = false;
119       warningChain = new SQLWarningChain();
120    }
121
122
123    protected void NotImplemented() throws java.sql.SQLException JavaDoc
124       {
125          throw new SQLException("Not implemented");
126       }
127
128
129    /**
130     * After this call getWarnings returns null until a new warning is
131     * reported for this ResultSet.
132     *
133     * @exception SQLException if a database-access error occurs.
134     */

135    public void clearWarnings() throws SQLException
136    {
137       warningChain.clearWarnings();
138    }
139
140    /**
141     * In some cases, it is desirable to immediately release a
142     * ResultSet's database and JDBC resources instead of waiting for
143     * this to happen when it is automatically closed; the close
144     * method provides this immediate release.
145     *
146     * <P><B>Note:</B> A ResultSet is automatically closed by the
147     * Statement that generated it when that Statement is closed,
148     * re-executed, or is used to retrieve the next result from a
149     * sequence of multiple results. A ResultSet is also automatically
150     * closed when it is garbage collected.
151     *
152     * @exception SQLException if a database-access error occurs.
153     */

154    public void close() throws SQLException
155    {
156       Exception JavaDoc exception = null;
157       
158       if (isClosed)
159       {
160          // nop ???
161
}
162       else
163       {
164          isClosed = true;
165          try
166          {
167             if (!hitEndOfData)
168             {
169                tds.discardResultSet(columnsInfo);
170                hitEndOfData = true;
171             }
172             else
173             {
174                // nop
175
}
176          }
177          catch(com.internetcds.jdbc.tds.TdsException e)
178          {
179              e.printStackTrace();
180             exception = e;
181       }
182          catch(java.io.IOException JavaDoc e)
183          {
184              e.printStackTrace();
185             exception = e;
186          }
187          
188          currentRow = null;
189          metaData = null;
190          columnsInfo = null;
191          stmt = null;
192          
193          if (exception != null)
194          {
195             throw new SQLException(exception.getMessage());
196          }
197       }
198    }
199
200
201    //----------------------------------------------------------------
202

203    /**
204     * Map a Resultset column name to a ResultSet column index.
205     *
206     * @param columnName the name of the column
207     * @return the column index
208     * @exception SQLException if a database-access error occurs.
209     */

210    public int findColumn(String JavaDoc columnName) throws SQLException
211    {
212       int i;
213
214       for(i=1; i<=columnsInfo.getColumnCount(); i++)
215       {
216          if (columnsInfo.getName(i).equalsIgnoreCase(columnName))
217          {
218             return i;
219          }
220          // XXX also need to look at the fully qualified name ie. table.column
221
}
222       throw new SQLException("No such column " + columnName);
223    }
224
225
226    /**
227     * A column value can be retrieved as a stream of ASCII characters
228     * and then read in chunks from the stream. This method is particularly
229     * suitable for retrieving large LONGVARCHAR values. The JDBC driver will
230     * do any necessary conversion from the database format into ASCII.
231     *
232     * <P><B>Note:</B> All the data in the returned stream must be
233     * read prior to getting the value of any other column. The next
234     * call to a get method implicitly closes the stream. . Also, a
235     * stream may return 0 for available() whether there is data
236     * available or not.
237     *
238     * @param columnIndex the first column is 1, the second is 2, ...
239     * @return a Java input stream that delivers the database column value
240     * as a stream of one byte ASCII characters. If the value is SQL NULL
241     * then the result is null.
242     * @exception SQLException if a database-access error occurs.
243     */

244    public java.io.InputStream JavaDoc getAsciiStream(int columnIndex) throws SQLException
245    {
246        String JavaDoc val = getString(columnIndex);
247        if (val == null)
248            return null;
249        try {
250            return new ByteArrayInputStream(val.getBytes("ASCII"));
251        } catch (UnsupportedEncodingException ue) {
252            // plain impossible with encoding ASCII
253
return null;
254        }
255    }
256
257
258    /**
259     * A column value can be retrieved as a stream of ASCII characters
260     * and then read in chunks from the stream. This method is particularly
261     * suitable for retrieving large LONGVARCHAR values. The JDBC driver will
262     * do any necessary conversion from the database format into ASCII.
263     *
264     * <P><B>Note:</B> All the data in the returned stream must
265     * be read prior to getting the value of any other column. The
266     * next call to a get method implicitly closes the stream.
267     *
268     * @param columnName is the SQL name of the column
269     * @return a Java input stream that delivers the database column value
270     * as a stream of one byte ASCII characters. If the value is SQL NULL
271     * then the result is null.
272     * @exception SQLException if a database-access error occurs.
273     */

274    public java.io.InputStream JavaDoc getAsciiStream(String JavaDoc columnName) throws SQLException
275    {
276       return getAsciiStream(findColumn(columnName));
277    }
278
279
280    /**
281     * Get the value of a column in the current row as a
282     * java.lang.BigDecimal object.
283     *
284     * @param columnIndex the first column is 1, the second is 2, ...
285     * @param scale the number of digits to the right of the decimal
286     * @return the column value; if the value is SQL NULL, the result is null
287     * @exception SQLException if a database-access error occurs.
288     */

289    public BigDecimal JavaDoc getBigDecimal(int columnIndex, int scale)
290       throws SQLException
291    {
292       Object JavaDoc tmp = getObject(columnIndex);
293       BigDecimal JavaDoc result = null;
294
295
296       if (tmp == null)
297       {
298          result = null;
299       }
300       else if (tmp instanceof java.lang.Double JavaDoc)
301       {
302          result = new BigDecimal JavaDoc(((Double JavaDoc)tmp).doubleValue());
303          result = result.setScale(scale, BigDecimal.ROUND_HALF_UP);
304       }
305       else if (tmp instanceof java.lang.Float JavaDoc)
306       {
307          result = new BigDecimal JavaDoc(((Float JavaDoc)tmp).doubleValue());
308          result = result.setScale(scale, BigDecimal.ROUND_HALF_UP);
309       }
310       else if (tmp instanceof java.lang.Number JavaDoc)
311       {
312          // This handles Byte, Short, Integer, and Long
313
result = BigDecimal.valueOf(((Number JavaDoc)tmp).longValue(), scale);
314       }
315       else if (tmp instanceof BigDecimal JavaDoc)
316       {
317          result = (BigDecimal JavaDoc)tmp;
318       }
319       else if (tmp instanceof java.lang.String JavaDoc)
320       {
321          try
322          {
323             result = new BigDecimal JavaDoc((String JavaDoc)tmp);
324          }
325          catch (NumberFormatException JavaDoc e)
326          {
327             throw new SQLException(e.getMessage());
328          }
329       }
330       return result;
331    }
332
333    /**
334     * Get the value of a column in the current row as a
335     * java.lang.BigDecimal object.
336     *
337     * @param columnName is the SQL name of the column
338     * @param scale the number of digits to the right of the decimal
339     * @return the column value; if the value is SQL NULL, the result is null
340     * @exception SQLException if a database-access error occurs.
341     */

342    public BigDecimal JavaDoc getBigDecimal(String JavaDoc columnName, int scale) throws SQLException
343    {
344       return getBigDecimal(findColumn(columnName), scale);
345    }
346
347
348    /**
349     * A column value can be retrieved as a stream of uninterpreted bytes
350     * and then read in chunks from the stream. This method is particularly
351     * suitable for retrieving large LONGVARBINARY values.
352     *
353     * <P><B>Note:</B> All the data in the returned stream must be
354     * read prior to getting the value of any other column. The next
355     * call to a get method implicitly closes the stream. Also, a
356     * stream may return 0 for available() whether there is data
357     * available or not.
358     *
359     * @param columnIndex the first column is 1, the second is 2, ...
360     * @return a Java input stream that delivers the database column value
361     * as a stream of uninterpreted bytes. If the value is SQL NULL
362     * then the result is null.
363     * @exception SQLException if a database-access error occurs.
364     */

365    public java.io.InputStream JavaDoc getBinaryStream(int columnIndex)
366       throws SQLException
367    {
368        byte[] bytes = getBytes(columnIndex);
369        if (bytes != null)
370            return new ByteArrayInputStream(bytes);
371        return null;
372    }
373
374
375    /**
376     * A column value can be retrieved as a stream of uninterpreted bytes
377     * and then read in chunks from the stream. This method is particularly
378     * suitable for retrieving large LONGVARBINARY values.
379     *
380     * <P><B>Note:</B> All the data in the returned stream must
381     * be read prior to getting the value of any other column. The
382     * next call to a get method implicitly closes the stream.
383     *
384     * @param columnName is the SQL name of the column
385     * @return a Java input stream that delivers the database column value
386     * as a stream of uninterpreted bytes. If the value is SQL NULL
387     * then the result is null.
388     * @exception SQLException if a database-access error occurs.
389     */

390    public java.io.InputStream JavaDoc getBinaryStream(String JavaDoc columnName)
391       throws SQLException
392    {
393       return getBinaryStream(findColumn(columnName));
394    }
395
396
397    /**
398     * Get the value of a column in the current row as a Java boolean.
399     *
400     * @param columnIndex the first column is 1, the second is 2, ...
401     * @return the column value; if the value is SQL NULL, the result is false
402     * @exception SQLException if a database-access error occurs.
403     */

404    public boolean getBoolean(int columnIndex) throws SQLException
405    {
406       Object JavaDoc obj = getObject(columnIndex);
407       boolean result;
408
409       if (obj == null)
410       {
411          result = false;
412       }
413       else
414       {
415          switch(getMetaData().getColumnType(columnIndex))
416          {
417             case java.sql.Types.TINYINT:
418             case java.sql.Types.SMALLINT:
419             case java.sql.Types.INTEGER:
420             case java.sql.Types.BIGINT:
421             case java.sql.Types.REAL:
422             case java.sql.Types.FLOAT:
423             case java.sql.Types.DOUBLE:
424             case java.sql.Types.DECIMAL:
425             case java.sql.Types.NUMERIC:
426             {
427                if (! (obj instanceof java.lang.Number JavaDoc))
428                {
429                   // Must be out of sync with the implementation of
430
// Tds.getRow() for this to happen.
431
throw new SQLException("Internal error");
432                }
433                // Would somebody like to tell what a true/false has
434
// to do with a double?
435
result = ((java.lang.Number JavaDoc)obj).intValue()!=0;
436                break;
437             }
438             case java.sql.Types.BIT:
439             {
440                if (! (obj instanceof Boolean JavaDoc))
441                {
442                   // Must be out of sync with the implementation of
443
// Tds.getRow() for this to happen.
444
throw new SQLException("Internal error");
445                }
446                result = ((Boolean JavaDoc)obj).booleanValue();
447                break;
448             }
449             case java.sql.Types.CHAR:
450             case java.sql.Types.VARCHAR:
451             case java.sql.Types.LONGVARCHAR:
452             {
453                // Okay, I'm really confused as to what you mean
454
// by a character string being true or false. What
455
// is the boolean value for "Let the wookie win"?
456
// But since the spec says I have to convert from
457
// character to boolean data...
458

459                if (! (obj instanceof String JavaDoc))
460                {
461                   // Must be out of sync with the implementation of
462
// Tds.getRow() for this to happen.
463
throw new SQLException("Internal error");
464                }
465                char ch = (((String JavaDoc)obj) + "n").charAt(0);
466
467                result = (ch=='Y')||(ch=='y')||(ch=='t')||(ch=='T');
468                break;
469             }
470             default:
471             {
472                throw new SQLException("Can't convert column " + columnIndex
473                                       + " from "
474                                       + obj.getClass().getName()
475                                       + " to boolean");
476             }
477          }
478       }
479       return result;
480    } // getBoolean()
481

482
483    /**
484     * Get the value of a column in the current row as a Java boolean.
485     *
486     * @param columnName is the SQL name of the column
487     * @return the column value; if the value is SQL NULL, the result is false
488     * @exception SQLException if a database-access error occurs.
489     */

490    public boolean getBoolean(String JavaDoc columnName) throws SQLException
491    {
492       return getBoolean(findColumn(columnName));
493    } // getBoolean()
494

495
496    /**
497     * Get the value of a column in the current row as a Java byte.
498     *
499     * @param columnIndex the first column is 1, the second is 2, ...
500     * @return the column value; if the value is SQL NULL, the result is 0
501     * @exception SQLException if a database-access error occurs.
502     */

503    public byte getByte(int columnIndex) throws SQLException
504    {
505       return (byte) getLong(columnIndex);
506    }
507
508
509    /**
510     * Get the value of a column in the current row as a Java byte.
511     *
512     * @param columnName is the SQL name of the column
513     * @return the column value; if the value is SQL NULL, the result is 0
514     * @exception SQLException if a database-access error occurs.
515     */

516    public byte getByte(String JavaDoc columnName) throws SQLException
517    {
518       return getByte(findColumn(columnName));
519    }
520
521
522    /**
523     * Get the value of a column in the current row as a Java byte array.
524     * The bytes represent the raw values returned by the driver.
525     *
526     * @param columnIndex the first column is 1, the second is 2, ...
527     * @return the column value; if the value is SQL NULL, the result is null
528     * @exception SQLException if a database-access error occurs.
529     */

530    public byte[] getBytes(int columnIndex) throws SQLException
531    {
532       byte result[];
533
534       try
535       {
536          Object JavaDoc tmp = currentRow.getElementAt(columnIndex);
537          lastGetWasNull = false;
538          if (tmp == null)
539          {
540             lastGetWasNull = true;
541             result = null;
542          }
543          else if (tmp instanceof byte[])
544          {
545             result = (byte[])tmp;
546          }
547          else if (tmp instanceof String JavaDoc)
548          {
549             result = tds.getEncoder().getBytes((String JavaDoc)tmp);
550          }
551          else
552          {
553             throw new SQLException("Can't convert column " + columnIndex
554                                    + " from "
555                                    + tmp.getClass().getName()
556                                    + " to byte[]");
557          }
558       }
559       catch (TdsException e)
560       {
561          e.printStackTrace();
562          throw new SQLException(e.getMessage());
563       }
564       return result;
565    }
566
567
568    /**
569     * Get the value of a column in the current row as a Java byte array.
570     * The bytes represent the raw values returned by the driver.
571     *
572     * @param columnName is the SQL name of the column
573     * @return the column value; if the value is SQL NULL, the result is null
574     * @exception SQLException if a database-access error occurs.
575     */

576    public byte[] getBytes(String JavaDoc columnName) throws SQLException
577    {
578       return getBytes(findColumn(columnName));
579    }
580
581
582    /**
583     * Get the name of the SQL cursor used by this ResultSet.
584     *
585     * <P>In SQL, a result table is retrieved through a cursor that is
586     * named. The current row of a result can be updated or deleted
587     * using a positioned update/delete statement that references the
588     * cursor name.
589     *
590     * <P>JDBC supports this SQL feature by providing the name of the
591     * SQL cursor used by a ResultSet. The current row of a ResultSet
592     * is also the current row of this SQL cursor.
593     *
594     * <P><B>Note:</B> If positioned update is not supported a
595     * SQLException is thrown
596     *
597     * @return the ResultSet's SQL cursor name
598     * @exception SQLException if a database-access error occurs.
599     */

600    public String JavaDoc getCursorName() throws SQLException
601    {
602       throw new SQLException("Not implemented (getCursorName)");
603    }
604
605
606    /**
607     * Get the value of a column in the current row as a java.sql.Date object.
608     *
609     * @param columnIndex the first column is 1, the second is 2, ...
610     * @return the column value; if the value is SQL NULL, the result is null
611     * @exception SQLException if a database-access error occurs.
612     */

613    public java.sql.Date JavaDoc getDate(int columnIndex) throws SQLException
614    {
615       java.sql.Date JavaDoc result = null;
616       java.sql.Timestamp JavaDoc tmp = getTimestamp(columnIndex);
617
618       if (tmp != null)
619       {
620          result = new java.sql.Date JavaDoc(tmp.getTime());
621       }
622       return result;
623    }
624
625
626    /**
627     * Get the value of a column in the current row as a java.sql.Date object.
628     *
629     * @param columnName is the SQL name of the column
630     * @return the column value; if the value is SQL NULL, the result is null
631     * @exception SQLException if a database-access error occurs.
632     */

633    public java.sql.Date JavaDoc getDate(String JavaDoc columnName) throws SQLException
634    {
635       return getDate(findColumn(columnName));
636    }
637
638
639    /**
640     * Get the value of a column in the current row as a Java double.
641     *
642     * @param columnIndex the first column is 1, the second is 2, ...
643     * @return the column value; if the value is SQL NULL, the result is 0
644     * @exception SQLException if a database-access error occurs.
645     */

646    public double getDouble(int columnIndex) throws SQLException
647    {
648       double result;
649       Object JavaDoc obj = getObject(columnIndex);
650
651       if (obj == null)
652       {
653          result = 0.0;
654       }
655       else
656       {
657          try
658          {
659             switch(getMetaData().getColumnType(columnIndex))
660             {
661                case java.sql.Types.TINYINT:
662                case java.sql.Types.SMALLINT:
663                case java.sql.Types.INTEGER:
664                {
665                   result = ((Number JavaDoc)obj).doubleValue();
666                   break;
667                }
668                case java.sql.Types.BIGINT:
669                {
670                   result = ((Number JavaDoc)obj).doubleValue();
671                   break;
672                }
673                case java.sql.Types.REAL:
674                {
675                   result = ((Float JavaDoc)obj).doubleValue();
676                   break;
677                }
678                case java.sql.Types.FLOAT:
679                case java.sql.Types.DOUBLE:
680                {
681                   result = ((Number JavaDoc)obj).doubleValue();
682                   break;
683                }
684                case java.sql.Types.CHAR:
685                case java.sql.Types.VARCHAR:
686                case java.sql.Types.LONGVARCHAR:
687                {
688                   try
689                   {
690                      Double JavaDoc d = new Double JavaDoc((String JavaDoc)obj);
691                      result = d.doubleValue();
692                   }
693                   catch (NumberFormatException JavaDoc e)
694                   {
695                      throw new SQLException(e.getMessage());
696                   }
697                   break;
698                }
699                case java.sql.Types.DECIMAL:
700                case java.sql.Types.NUMERIC:
701                {
702                   result = ((BigDecimal JavaDoc)obj).doubleValue();
703                   break;
704                }
705                case java.sql.Types.BIT:
706                {
707                   // XXX according to JDBC spec we need to handle these
708
// for now just fall through
709
}
710                default:
711                {
712                   throw new SQLException("Internal error. "
713                                          + "Don't know how to convert from "
714                                          + "java.sql.Types." +
715                                          TdsUtil.javaSqlTypeToString(getMetaData().getColumnType(columnIndex))
716                                          + " to an Dboule");
717                }
718             }
719          }
720          catch(ClassCastException JavaDoc e)
721          {
722             throw new SQLException("Couldn't convert column " + columnIndex
723                                    + " to an long. "
724                                    + e.getMessage());
725          }
726       }
727       return result;
728    } /* getDouble() */
729
730
731    /**
732     * Get the value of a column in the current row as a Java double.
733     *
734     * @param columnName is the SQL name of the column
735     * @return the column value; if the value is SQL NULL, the result is 0
736     * @exception SQLException if a database-access error occurs.
737     */

738    public double getDouble(String JavaDoc columnName) throws SQLException
739    {
740       return getDouble(findColumn(columnName));
741    }
742
743
744    /**
745     * Get the value of a column in the current row as a Java float.
746     *
747     * @param columnIndex the first column is 1, the second is 2, ...
748     * @return the column value; if the value is SQL NULL, the result is 0
749     * @exception SQLException if a database-access error occurs.
750     */

751    public float getFloat(int columnIndex) throws SQLException
752    {
753       return (float)getDouble(columnIndex);
754    }
755
756
757    /**
758     * Get the value of a column in the current row as a Java float.
759     *
760     * @param columnName is the SQL name of the column
761     * @return the column value; if the value is SQL NULL, the result is 0
762     * @exception SQLException if a database-access error occurs.
763     */

764    public float getFloat(String JavaDoc columnName) throws SQLException
765    {
766       return getFloat(findColumn(columnName));
767    }
768
769
770    /**
771     * Get the value of a column in the current row as a Java int.
772     *
773     * @param columnIndex the first column is 1, the second is 2, ...
774     * @return the column value; if the value is SQL NULL, the result is 0
775     * @exception SQLException if a database-access error occurs.
776     */

777    public int getInt(int columnIndex) throws SQLException
778    {
779       return (int) getLong(columnIndex);
780    }
781
782
783    /**
784     * Get the value of a column in the current row as a Java int.
785     *
786     * @param columnName is the SQL name of the column
787     * @return the column value; if the value is SQL NULL, the result is 0
788     * @exception SQLException if a database-access error occurs.
789     */

790    public int getInt(String JavaDoc columnName) throws SQLException
791    {
792       return getInt(findColumn(columnName));
793    }
794
795
796    /**
797     * Get the value of a column in the current row as a Java long.
798     *
799     * @param columnIndex the first column is 1, the second is 2, ...
800     * @return the column value; if the value is SQL NULL, the result is 0
801     * @exception SQLException if a database-access error occurs.
802     */

803    public long getLong(int columnIndex) throws SQLException
804    {
805       long result = 0;
806       Object JavaDoc obj = getObject(columnIndex);
807
808       if (obj == null)
809       {
810          result = 0;
811       }
812       else
813       {
814          try
815          {
816             switch(getMetaData().getColumnType(columnIndex))
817             {
818                case java.sql.Types.TINYINT:
819                case java.sql.Types.SMALLINT:
820                case java.sql.Types.INTEGER:
821                {
822                   result = ((Number JavaDoc)obj).longValue();
823                   break;
824                }
825                case java.sql.Types.BIGINT:
826                {
827                   result = ((Number JavaDoc)obj).longValue();
828                   break;
829                }
830                case java.sql.Types.REAL:
831                case java.sql.Types.FLOAT:
832                case java.sql.Types.DOUBLE:
833                {
834                   result = ((Number JavaDoc)obj).longValue();
835                   break;
836                }
837                case java.sql.Types.CHAR:
838                case java.sql.Types.VARCHAR:
839                case java.sql.Types.LONGVARCHAR:
840                {
841                   try
842                   {
843                      Long JavaDoc i = new Long JavaDoc((String JavaDoc)obj);
844                      result = i.longValue();
845                   }
846                   catch (NumberFormatException JavaDoc e)
847                   {
848                      throw new SQLException(e.getMessage());
849                   }
850                   break;
851                }
852                case java.sql.Types.NUMERIC:
853                {
854                   result = ((Number JavaDoc)obj).longValue();
855                   break;
856                }
857                case java.sql.Types.DECIMAL:
858                {
859                   result = ((Number JavaDoc)obj).longValue();
860                   break;
861                }
862                case java.sql.Types.BIT:
863                {
864                   // XXX according to JDBC spec we need to handle these
865
// for now just fall through
866
}
867                default:
868                {
869                   throw new SQLException("Internal error. "
870                                          + "Don't know how to convert from "
871                                          + "java.sql.Types " +
872                                          TdsUtil.javaSqlTypeToString(getMetaData().getColumnType(columnIndex))
873                                          + " to an long");
874                }
875             }
876          }
877          catch(ClassCastException JavaDoc e)
878          {
879             throw new SQLException("Couldn't convert column " + columnIndex
880                                    + " to an long. "
881                                    + e.getMessage());
882          }
883       }
884       return result;
885    } /* getLong() */
886
887
888    /**
889     * Get the value of a column in the current row as a Java long.
890     *
891     * @param columnName is the SQL name of the column
892     * @return the column value; if the value is SQL NULL, the result is 0
893     * @exception SQLException if a database-access error occurs.
894     */

895    public long getLong(String