4 import java
.math
.BigDecimal
;
7 import java
.sql
.Connection
;
8 import java
.sql
.Statement
;
9 import java
.sql
.SQLException
;
10 import java
.sql
.ResultSet
;
11 import java
.sql
.ResultSetMetaData
;
12 import java
.sql
.SQLWarning
;
14 import java
.io
.InputStream
;
15 import java
.io
.InputStreamReader
;
16 import java
.io
.StringBufferInputStream
;
21 import java
.sql
.Array
;
22 import java
.sql
.Types
;
24 public class JdbcSqlResultSet
extends JSqlError
implements ResultSet
, JSqlErrorType
26 public JdbcSqlStatement stmt
; // This guy creates me
27 public JdbcSqlResultSetMetaData rsmd
;
29 public boolean isClosed
;
35 rsmd
= new JdbcSqlResultSetMetaData();
39 void setStmt( JdbcSqlStatement jdbcStmt
)
42 rsmd
.setStmt( jdbcStmt
);
46 protected void finalize ()
50 if(!isClosed
) close();
54 System
.out
.println(e
);
59 public void close() throws SQLException
61 if( isClosed
) return;
65 //rsmd.close(); //commented by praba
66 //after close the app can reexecute.
67 if (stmt
!= null) stmt
.closeScan();
72 public boolean next () throws SQLException
74 if( isClosed
) throw getException( CSQL_INVALID_STATE
);
76 if( 0 == stmt
.jniStmt
.next() )
85 public ResultSetMetaData
getMetaData () throws SQLException
87 if( isClosed
) throw getException( CSQL_INVALID_STATE
);
90 public SQLWarning
getWarnings() throws SQLException
94 public void clearWarnings() throws SQLException
98 public int findColumn (String colName
) throws SQLException
100 if( isClosed
) throw getException( CSQL_INVALID_STATE
);
102 int colnum
= stmt
.jniStmt
.findColumn( colName
);
105 public int getType() throws SQLException
107 return( ResultSet
.TYPE_FORWARD_ONLY
);
109 public int getConcurrency() throws SQLException
111 return( ResultSet
.CONCUR_READ_ONLY
);
113 public Statement
getStatement() throws SQLException
115 if( isClosed
) throw getException( CSQL_INVALID_STATE
);
118 public boolean isFirst() throws SQLException
120 if( isClosed
) throw getException( CSQL_INVALID_STATE
);
127 public boolean isBeforeFirst() throws SQLException
129 if( isClosed
) throw getException( CSQL_INVALID_STATE
);
136 public boolean isAfterLast() throws SQLException
138 if( isClosed
) throw getException( CSQL_INVALID_STATE
);
146 // Provide data to application
148 public short getShort (int colNum
) throws SQLException
150 if( isClosed
|| curRow
< 0 ) throw getException( CSQL_INVALID_STATE
);
152 short out
= stmt
.jniStmt
.getShort( colNum
- 1 );
153 if( false ) throw new SQLException();
156 public short getShort (String colName
) throws SQLException
158 if( isClosed
) throw getException( CSQL_INVALID_STATE
);
159 return( getShort( findColumn( colName
) ) );
163 public int getInt (int colNum
) throws SQLException
165 if( isClosed
|| curRow
< 0 ) throw getException( CSQL_INVALID_STATE
);
167 int out
= stmt
.jniStmt
.getInt( colNum
- 1 );
168 if( false ) throw new SQLException();
171 public int getInt (String colName
) throws SQLException
173 if( isClosed
) throw getException( CSQL_INVALID_STATE
);
174 return( getInt( findColumn( colName
) ) );
178 public long getLong (int colNum
) throws SQLException
180 if( isClosed
|| curRow
< 0 ) throw getException( CSQL_INVALID_STATE
);
182 long out
= stmt
.jniStmt
.getLong( colNum
-1 );
183 if( false ) throw new SQLException();
186 public long getLong (String colName
) throws SQLException
188 if( isClosed
) throw getException( CSQL_INVALID_STATE
);
189 return( getLong( findColumn( colName
) ) );
193 public byte getByte (int colNum
) throws SQLException
195 if( isClosed
|| curRow
< 0 ) throw getException( CSQL_INVALID_STATE
);
197 byte out
= stmt
.jniStmt
.getByte( colNum
-1 );
198 if( false ) throw new SQLException();
201 public byte getByte (String colName
) throws SQLException
203 if( isClosed
) throw getException( CSQL_INVALID_STATE
);
204 return( getByte( findColumn( colName
) ) );
208 public float getFloat (int colNum
) throws SQLException
210 if( isClosed
|| curRow
< 0 ) throw getException( CSQL_INVALID_STATE
);
212 float out
= stmt
.jniStmt
.getFloat( colNum
-1 );
213 if( false ) throw new SQLException();
216 public float getFloat (String colName
) throws SQLException
218 if( isClosed
) throw getException( CSQL_INVALID_STATE
);
219 return( getFloat( findColumn( colName
) ) );
223 public double getDouble (int colNum
) throws SQLException
225 if( isClosed
|| curRow
< 0 ) throw getException( CSQL_INVALID_STATE
);
227 double out
= stmt
.jniStmt
.getDouble( colNum
-1 );
228 if( false ) throw new SQLException();
231 public double getDouble (String colName
) throws SQLException
233 if( isClosed
) throw getException( CSQL_INVALID_STATE
);
234 return( getDouble( findColumn( colName
) ) );
238 public BigDecimal
getBigDecimal( int colNum
)
241 if( isClosed
|| curRow
< 0 ) throw getException( CSQL_INVALID_STATE
);
243 throw getException( CSQL_NOT_SUPPORTED
);
246 // BigDecimal out = new BigDecimal( stmt.jniStmt.getBigDecimal( colNum-1 ) );
249 public BigDecimal
getBigDecimal(String colName
)
252 if( isClosed
) throw getException( CSQL_INVALID_STATE
);
253 return( getBigDecimal( findColumn( colName
) ) );
255 public BigDecimal
getBigDecimal (int colNum
, int scale
)
258 return( getBigDecimal( colNum
) );
260 public BigDecimal
getBigDecimal (String colName
, int scale
)
263 return( getBigDecimal( colName
) );
267 public String
getString(int colNum
) throws SQLException
269 if( isClosed
|| curRow
< 0 ) throw getException( CSQL_INVALID_STATE
);
272 String out
= stmt
.jniStmt
.getString( colNum
-1 );
276 public String
getString (String colName
) throws SQLException
278 return( getString( findColumn( colName
) ) );
280 public InputStream
getAsciiStream(int colNum
) throws SQLException
282 if( isClosed
|| curRow
< 0 ) throw getException( CSQL_INVALID_STATE
);
284 String out
= stmt
.jniStmt
.getString( colNum
-1 );
286 return( new StringBufferInputStream( out
) );
288 public java
.io
.InputStream
getAsciiStream (String colName
) throws SQLException
290 return( getAsciiStream( findColumn( colName
) ) );
292 public java
.io
.Reader
getCharacterStream(int colNum
)
295 if( isClosed
|| curRow
< 0 ) throw getException( CSQL_INVALID_STATE
);
297 InputStream iS
= getAsciiStream( colNum
);
301 return( new InputStreamReader( iS
) );
303 public java
.io
.Reader
getCharacterStream(String colName
)
306 return( getCharacterStream( findColumn( colName
) ) );
310 public boolean getBoolean (int colNum
) throws SQLException
312 if( isClosed
|| curRow
< 0 ) throw getException( CSQL_INVALID_STATE
);
314 boolean out
= stmt
.jniStmt
.getBoolean( colNum
-1 );
318 public boolean getBoolean (String colName
) throws SQLException
320 return( getBoolean( findColumn( colName
) ) );
324 public byte [] getBytes(int colNum
) throws SQLException
326 if( isClosed
|| curRow
< 0 ) throw getException( CSQL_INVALID_STATE
);
328 throw getException( CSQL_NOT_SUPPORTED
);
329 //byte[] out = stmt.jniStmt.getBytes( colNum-1 );
332 public byte[] getBytes (String colName
) throws SQLException
334 return( getBytes( findColumn( colName
) ) );
338 public java
.sql
.Date
getDate (int colNum
) throws SQLException
340 if( isClosed
|| curRow
< 0 ) throw getException( CSQL_INVALID_STATE
);
342 java
.sql
.Date out
= stmt
.jniStmt
.getDate( colNum
-1 );
346 public java
.sql
.Date
getDate(int colNum
, java
.util
.Calendar cal
)
349 return( getDate( colNum
) );
351 public java
.sql
.Date
getDate (String colNum
) throws SQLException
353 return( getDate( findColumn( colNum
) ) );
355 public java
.sql
.Date
getDate(String colName
, java
.util
.Calendar cal
)
358 return( getDate( colName
) );
362 public java
.sql
.Time
getTime (int colNum
) throws SQLException
364 if( isClosed
|| curRow
< 0 ) throw getException( CSQL_INVALID_STATE
);
367 java
.sql
.Time out
= stmt
.jniStmt
.getTime( colNum
-1 );
371 public java
.sql
.Time
getTime(int colNum
, java
.util
.Calendar cal
)
374 return( getTime( colNum
) );
376 public java
.sql
.Time
getTime (String colName
) throws SQLException
378 return( getTime( findColumn( colName
) ) );
380 public java
.sql
.Time
getTime(String colName
, java
.util
.Calendar cal
)
383 return( getTime( colName
) );
387 public java
.sql
.Timestamp
getTimestamp (int colNum
)
390 if( isClosed
|| curRow
< 0 ) throw getException( CSQL_INVALID_STATE
);
392 java
.sql
.Timestamp out
= stmt
.jniStmt
.getTimestamp( colNum
-1 );
396 public java
.sql
.Timestamp
getTimestamp(int colNum
,
397 java
.util
.Calendar cal
) throws SQLException
399 return( getTimestamp( colNum
) );
401 public java
.sql
.Timestamp
getTimestamp (String colName
)
404 return( getTimestamp( findColumn( colName
) ) );
406 public java
.sql
.Timestamp
getTimestamp(String colName
,
407 java
.util
.Calendar cal
) throws SQLException
409 return( getTimestamp( colName
) );
412 public Object
getObject(int colNum
) throws SQLException
414 Object obj
= new String("no obj");
416 if( isClosed
|| curRow
< 0 ) throw getException( CSQL_INVALID_STATE
);
418 switch ( rsmd
.getColumnType( colNum
) )
421 obj
= new Double( getDouble( colNum
) ); break;
423 obj
= new Float( getFloat( colNum
) ); break;
426 obj
= getBigDecimal( colNum
); break;
429 obj
= new Long( getLong( colNum
) ); break;
431 obj
= new Integer( getInt( colNum
) ); break;
433 obj
= new Short( getShort( colNum
) ); break;
435 obj
= new Byte( getByte( colNum
) ); break;
437 obj
= new Boolean( getBoolean( colNum
) ); break;
440 obj
= getDate( colNum
); break;
442 obj
= getTime( colNum
); break;
443 case Types
.TIMESTAMP
:
444 obj
= getTimestamp( colNum
); break;
447 obj
= getString( colNum
); break;
449 obj
= getString( colNum
); break;
451 case Types
.VARBINARY
:
452 obj
= getBytes( colNum
); break;
454 default: throw getException( CSQL_INVALID_DATATYPE
);
456 // Return null if value read is null //TODO
462 public Object
getObject (String colName
) throws SQLException
464 return( getObject( findColumn( colName
) ) );
466 public Object
getObject(int i
, java
.util
.Map map
) throws SQLException
468 return( getObject( i
) );
470 public Object
getObject(String colName
, java
.util
.Map map
)
473 return( getObject( colName
) );
476 public int getRow() throws SQLException
481 return( (int) curRow
+ 1 );
484 // UN-SUPPORTED API's
485 public boolean wasNull () throws SQLException
// TODO
487 if( isClosed
) throw getException( CSQL_INVALID_STATE
);
488 throw getException( CSQL_NOT_SUPPORTED
);
489 //return( stmt.jniStmt.wasNull() );
491 public String
getCursorName () throws SQLException
493 throw getException( CSQL_NOT_SUPPORTED
);
495 public boolean absolute( int row
) throws SQLException
497 throw getException( CSQL_NOT_SUPPORTED
);
499 public void beforeFirst() throws SQLException
501 throw getException( CSQL_NOT_SUPPORTED
);
503 public void afterLast() throws SQLException
505 throw getException( CSQL_NOT_SUPPORTED
);
507 public boolean first() throws SQLException
509 throw getException( CSQL_NOT_SUPPORTED
);
511 public boolean last() throws SQLException
513 throw getException( CSQL_NOT_SUPPORTED
);
515 public boolean relative( int rows
) throws SQLException
517 throw getException( CSQL_NOT_SUPPORTED
);
519 public boolean previous() throws SQLException
521 throw getException( CSQL_NOT_SUPPORTED
);
523 public void setFetchDirection(int direction
) throws SQLException
525 throw getException( CSQL_NOT_SUPPORTED
);
527 public int getFetchDirection() throws SQLException
529 throw getException( CSQL_NOT_SUPPORTED
);
531 public void setFetchSize(int rows
) throws SQLException
533 throw getException( CSQL_NOT_SUPPORTED
);
535 public int getFetchSize() throws SQLException
537 throw getException( CSQL_NOT_SUPPORTED
);
539 public InputStream
getUnicodeStream(int colNum
) throws SQLException
541 throw getException( CSQL_NOT_SUPPORTED
);
543 public InputStream
getBinaryStream(int colNum
) throws SQLException
545 throw getException( CSQL_NOT_SUPPORTED
);
547 public java
.io
.InputStream
getUnicodeStream (String colName
) throws SQLException
549 throw getException( CSQL_NOT_SUPPORTED
);
551 public java
.io
.InputStream
getBinaryStream (String colName
) throws SQLException
553 throw getException( CSQL_NOT_SUPPORTED
);
555 public void setMaxRows(int maxRows
) throws SQLException
557 throw getException( CSQL_NOT_SUPPORTED
);
559 public void setMaxFieldSize(int maxFieldSize
) throws SQLException
561 throw getException( CSQL_NOT_SUPPORTED
);
563 public boolean rowUpdated() throws SQLException
565 throw getException( CSQL_NOT_SUPPORTED
);
567 public boolean rowInserted() throws SQLException
569 throw getException( CSQL_NOT_SUPPORTED
);
571 public boolean rowDeleted() throws SQLException
573 throw getException( CSQL_NOT_SUPPORTED
);
575 public void updateNull(int colNum
) throws SQLException
577 throw getException( CSQL_NOT_SUPPORTED
);
579 public void updateBoolean(int colNum
, boolean x
) throws SQLException
581 throw getException( CSQL_NOT_SUPPORTED
);
583 public void updateByte(int colNum
, byte x
) throws SQLException
585 throw getException( CSQL_NOT_SUPPORTED
);
587 public void updateShort(int colNum
, short x
) throws SQLException
589 throw getException( CSQL_NOT_SUPPORTED
);
591 public void updateInt(int colNum
, int x
) throws SQLException
593 throw getException( CSQL_NOT_SUPPORTED
);
595 public void updateLong(int colNum
, long x
) throws SQLException
597 throw getException( CSQL_NOT_SUPPORTED
);
599 public void updateFloat(int colNum
, float x
) throws SQLException
601 throw getException( CSQL_NOT_SUPPORTED
);
603 public void updateDouble(int colNum
, double x
) throws SQLException
605 throw getException( CSQL_NOT_SUPPORTED
);
607 public void updateBigDecimal(int colNum
, BigDecimal x
) throws SQLException
609 throw getException( CSQL_NOT_SUPPORTED
);
611 public void updateString(int colNum
, String x
) throws SQLException
613 throw getException( CSQL_NOT_SUPPORTED
);
615 public void updateBytes(int colNum
, byte x
[]) throws SQLException
617 throw getException( CSQL_NOT_SUPPORTED
);
619 public void updateDate(int colNum
, java
.sql
.Date x
) throws SQLException
621 throw getException( CSQL_NOT_SUPPORTED
);
623 public void updateTime(int colNum
, java
.sql
.Time x
) throws SQLException
625 throw getException( CSQL_NOT_SUPPORTED
);
627 public void updateTimestamp(int colNum
, java
.sql
.Timestamp x
)
630 throw getException( CSQL_NOT_SUPPORTED
);
632 public void updateAsciiStream(int colNum
,
633 java
.io
.InputStream x
, int length
) throws SQLException
635 throw getException( CSQL_NOT_SUPPORTED
);
637 public void updateBinaryStream(int colNum
,
638 java
.io
.InputStream x
, int length
) throws SQLException
640 throw getException( CSQL_NOT_SUPPORTED
);
642 public void updateCharacterStream(int colNum
,
643 java
.io
.Reader x
, int length
) throws SQLException
645 throw getException( CSQL_NOT_SUPPORTED
);
647 public void updateNull(String colName
) throws SQLException
649 throw getException( CSQL_NOT_SUPPORTED
);
651 public void updateBoolean(String colName
, boolean x
) throws SQLException
653 throw getException( CSQL_NOT_SUPPORTED
);
655 public void updateByte(String colName
, byte x
) throws SQLException
657 throw getException( CSQL_NOT_SUPPORTED
);
659 public void updateShort(String colName
, short x
) throws SQLException
661 throw getException( CSQL_NOT_SUPPORTED
);
663 public void updateInt(String colName
, int x
) throws SQLException
665 throw getException( CSQL_NOT_SUPPORTED
);
667 public void updateLong(String colName
, long x
) throws SQLException
669 throw getException( CSQL_NOT_SUPPORTED
);
671 public void updateFloat(String colName
, float x
) throws SQLException
673 throw getException( CSQL_NOT_SUPPORTED
);
675 public void updateDouble(String colName
, double x
) throws SQLException
677 throw getException( CSQL_NOT_SUPPORTED
);
679 public void updateBigDecimal(String colName
, BigDecimal x
)
682 throw getException( CSQL_NOT_SUPPORTED
);
684 public void updateString(String colName
, String x
) throws SQLException
686 throw getException( CSQL_NOT_SUPPORTED
);
688 public void updateBytes(String colName
, byte x
[]) throws SQLException
690 throw getException( CSQL_NOT_SUPPORTED
);
692 public void updateDate(String colName
, java
.sql
.Date x
) throws SQLException
694 throw getException( CSQL_NOT_SUPPORTED
);
696 public void updateTime(String colName
, java
.sql
.Time x
) throws SQLException
698 throw getException( CSQL_NOT_SUPPORTED
);
700 public void updateTimestamp(String colName
, java
.sql
.Timestamp x
)
703 throw getException( CSQL_NOT_SUPPORTED
);
705 public void updateAsciiStream(String colName
,
706 java
.io
.InputStream x
, int length
) throws SQLException
708 throw getException( CSQL_NOT_SUPPORTED
);
710 public void updateBinaryStream(String colName
,
711 java
.io
.InputStream x
, int length
) throws SQLException
713 throw getException( CSQL_NOT_SUPPORTED
);
715 public void updateCharacterStream(String colName
,
716 java
.io
.Reader reader
, int length
) throws SQLException
718 throw getException( CSQL_NOT_SUPPORTED
);
720 public void updateObject(int colNum
, Object x
, int scale
)
723 throw getException( CSQL_NOT_SUPPORTED
);
725 public void updateObject(int colNum
, Object x
) throws SQLException
727 throw getException( CSQL_NOT_SUPPORTED
);
729 public void insertRow() throws SQLException
731 throw getException( CSQL_NOT_SUPPORTED
);
733 public void updateRow() throws SQLException
735 throw getException( CSQL_NOT_SUPPORTED
);
737 public void deleteRow() throws SQLException
739 throw getException( CSQL_NOT_SUPPORTED
);
741 public void refreshRow() throws SQLException
743 throw getException( CSQL_NOT_SUPPORTED
);
745 public void cancelRowUpdates() throws SQLException
747 throw getException( CSQL_NOT_SUPPORTED
);
749 public void moveToInsertRow() throws SQLException
751 throw getException( CSQL_NOT_SUPPORTED
);
753 public void moveToCurrentRow() throws SQLException
755 throw getException( CSQL_NOT_SUPPORTED
);
757 public Ref
getRef(int i
) throws SQLException
759 throw getException( CSQL_NOT_SUPPORTED
);
761 public Blob
getBlob(int i
) throws SQLException
763 throw getException( CSQL_NOT_SUPPORTED
);
765 public Clob
getClob(int i
) throws SQLException
767 throw getException( CSQL_NOT_SUPPORTED
);
769 public Array
getArray(int i
) throws SQLException
771 throw getException( CSQL_NOT_SUPPORTED
);
773 public Ref
getRef(String colName
) throws SQLException
775 throw getException( CSQL_NOT_SUPPORTED
);
777 public Blob
getBlob(String colName
) throws SQLException
779 throw getException( CSQL_NOT_SUPPORTED
);
781 public Clob
getClob(String colName
) throws SQLException
783 throw getException( CSQL_NOT_SUPPORTED
);
785 public Array
getArray(String colName
) throws SQLException
787 throw getException( CSQL_NOT_SUPPORTED
);
789 public boolean isLast() throws SQLException
791 throw getException( CSQL_NOT_SUPPORTED
);
793 public void updateObject(String colName
, Object x
) throws SQLException
795 throw getException( CSQL_NOT_SUPPORTED
);
797 public void updateObject(String colName
, Object x
, int scale
)
800 throw getException( CSQL_NOT_SUPPORTED
);
802 public URL
getURL(int colNum
)
805 throw getException( CSQL_NOT_SUPPORTED
);
807 public URL
getURL(String colName
)
810 throw getException( CSQL_NOT_SUPPORTED
);
812 public void updateRef(int colNum
, Ref x
)
815 throw getException( CSQL_NOT_SUPPORTED
);
817 public void updateRef(String colName
, Ref x
)
820 throw getException( CSQL_NOT_SUPPORTED
);
822 public void updateBlob(int colNum
, Blob x
)
825 throw getException( CSQL_NOT_SUPPORTED
);
827 public void updateBlob(String colName
, Blob x
)
830 throw getException( CSQL_NOT_SUPPORTED
);
832 public void updateClob(int colNum
, Clob x
)
835 throw getException( CSQL_NOT_SUPPORTED
);
837 public void updateClob(String colName
, Clob x
)
840 throw getException( CSQL_NOT_SUPPORTED
);
842 public void updateArray(int colNum
, Array x
)
845 throw getException( CSQL_NOT_SUPPORTED
);
847 public void updateArray(String colName
, Array x
)
850 throw getException( CSQL_NOT_SUPPORTED
);