1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.orangesignal.csv;
18
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.io.Reader;
22 import java.io.StringReader;
23 import java.math.BigDecimal;
24 import java.net.MalformedURLException;
25 import java.net.URL;
26 import java.sql.Array;
27 import java.sql.Blob;
28 import java.sql.Clob;
29 import java.sql.Date;
30 import java.sql.NClob;
31 import java.sql.Ref;
32 import java.sql.ResultSet;
33 import java.sql.RowId;
34 import java.sql.SQLException;
35 import java.sql.SQLFeatureNotSupportedException;
36 import java.sql.SQLWarning;
37 import java.sql.SQLXML;
38 import java.sql.Statement;
39 import java.sql.Time;
40 import java.sql.Timestamp;
41 import java.text.DateFormat;
42 import java.text.ParseException;
43 import java.util.Calendar;
44 import java.util.List;
45 import java.util.Map;
46
47 import javax.sql.rowset.serial.SerialBlob;
48 import javax.sql.rowset.serial.SerialClob;
49
50
51
52
53
54
55 public class CsvResultSet implements ResultSet {
56
57 private CsvReader reader;
58
59
60
61
62 private CsvResultSetMetaData meta;
63
64
65
66
67 private List<String> row;
68
69
70
71
72 private int rowNumber = 0;
73
74
75
76
77 private boolean wasNull;
78
79
80
81
82
83
84
85
86 public CsvResultSet(final CsvReader reader) throws IOException {
87 if (reader == null) {
88 throw new IllegalArgumentException("CsvReader must not be null");
89 }
90 this.reader = reader;
91 this.meta = new CsvResultSetMetaData(reader);
92 }
93
94
95
96 private void ensureOpen() throws SQLException {
97 if (reader == null) {
98 throw new SQLException("Stream closed");
99 }
100 }
101
102 @Override
103 public boolean next() throws SQLException {
104 ensureOpen();
105 try {
106 row = reader.readValues();
107 if (row != null) {
108 rowNumber++;
109 return true;
110 }
111 return false;
112 } catch (final IOException e) {
113 throw new SQLException(e.getMessage(), e);
114 }
115 }
116
117 @Override
118 public void close() {
119 try {
120 reader.close();
121 } catch (final IOException e) {
122
123 }
124 reader = null;
125 meta = null;
126 row = null;
127 rowNumber = 0;
128 wasNull = false;
129 }
130
131 @Override
132 public boolean wasNull() throws SQLException {
133 ensureOpen();
134 return wasNull;
135 }
136
137
138
139 @Override
140 public String getString(final int columnIndex) throws SQLException {
141 ensureOpen();
142 if (row == null) {
143 throw new SQLException("No data is available");
144 }
145 if (columnIndex < 1 || columnIndex > row.size()) {
146 throw new SQLException(String.format("Invalid column index %d", columnIndex));
147 }
148 final String s = row.get(columnIndex - 1);
149 wasNull = s == null;
150 return s;
151 }
152
153 @Override
154 public boolean getBoolean(final int columnIndex) throws SQLException {
155 final String s = getString(columnIndex);
156 if (s == null) {
157 return false;
158 } else if ("1".equalsIgnoreCase(s)) {
159 return true;
160 } else if ("0".equalsIgnoreCase(s)) {
161 return false;
162 } else if ("true".equalsIgnoreCase(s)) {
163 return true;
164 } else if ("false".equalsIgnoreCase(s)) {
165 return false;
166 } else if ("on".equalsIgnoreCase(s)) {
167 return true;
168 } else if ("off".equalsIgnoreCase(s)) {
169 return false;
170 } else if ("yes".equalsIgnoreCase(s)) {
171 return true;
172 } else if ("no".equalsIgnoreCase(s)) {
173 return false;
174 }
175
176 throw new SQLException(String.format("Bad format for BOOLEAN '%s' in column %d.", s, columnIndex));
177 }
178
179 @Override
180 public byte getByte(final int columnIndex) throws SQLException {
181 final String s = getString(columnIndex);
182 if (s == null) {
183 return 0;
184 }
185 return Byte.valueOf(s).byteValue();
186 }
187
188 @Override
189 public short getShort(final int columnIndex) throws SQLException {
190 final String s = getString(columnIndex);
191 if (s == null) {
192 return 0;
193 }
194 return Short.valueOf(s).shortValue();
195 }
196
197 @Override
198 public int getInt(final int columnIndex) throws SQLException {
199 final String s = getString(columnIndex);
200 if (s == null) {
201 return 0;
202 }
203 return Integer.valueOf(s).intValue();
204 }
205
206 @Override
207 public long getLong(final int columnIndex) throws SQLException {
208 final String s = getString(columnIndex);
209 if (s == null) {
210 return 0L;
211 }
212 return Long.valueOf(s).longValue();
213 }
214
215 @Override
216 public float getFloat(final int columnIndex) throws SQLException {
217 final String s = getString(columnIndex);
218 if (s == null) {
219 return 0F;
220 }
221 return Float.valueOf(s).floatValue();
222 }
223
224 @Override
225 public double getDouble(final int columnIndex) throws SQLException {
226 final String s = getString(columnIndex);
227 if (s == null) {
228 return 0D;
229 }
230 return Double.valueOf(s).doubleValue();
231 }
232
233
234
235
236
237 @SuppressWarnings("deprecation")
238 @Override
239 public BigDecimal getBigDecimal(final int columnIndex, final int scale) throws SQLFeatureNotSupportedException {
240 throw new SQLFeatureNotSupportedException("getBigDecimal(int, int) not supported");
241 }
242
243 @Override
244 public byte[] getBytes(final int columnIndex) throws SQLException {
245 final String s = getString(columnIndex);
246 if (s == null) {
247 return null;
248 }
249 return s.getBytes();
250 }
251
252 @Override
253 public Date getDate(final int columnIndex) throws SQLException {
254 final String s = getString(columnIndex);
255 if (s == null) {
256 return null;
257 }
258 try {
259 return new Date(DateFormat.getDateInstance().parse(s).getTime());
260 } catch (final ParseException e) {
261 throw new SQLException(String.format("Bad format for DATE '%s' in column %d.", s, columnIndex), e);
262 }
263 }
264
265 @Override
266 public Time getTime(final int columnIndex) throws SQLException {
267 final String s = getString(columnIndex);
268 if (s == null) {
269 return null;
270 }
271 try {
272 return new Time(DateFormat.getTimeInstance().parse(s).getTime());
273 } catch (final ParseException e) {
274 throw new SQLException(String.format("Bad format for TIME '%s' in column %d.", s, columnIndex), e);
275 }
276 }
277
278 @Override
279 public Timestamp getTimestamp(final int columnIndex) throws SQLException {
280 final String s = getString(columnIndex);
281 if (s == null) {
282 return null;
283 }
284 try {
285 return new Timestamp(DateFormat.getDateTimeInstance().parse(s).getTime());
286 } catch (final ParseException e) {
287 throw new SQLException(String.format("Bad format for TIMESTAMP '%s' in column %d.", s, columnIndex), e);
288 }
289 }
290
291 @Override
292 public InputStream getAsciiStream(final int columnIndex) throws SQLException {
293 final Clob clob = getClob(columnIndex);
294 if (clob == null) {
295 return null;
296 }
297 return clob.getAsciiStream();
298 }
299
300
301
302
303
304 @SuppressWarnings("deprecation")
305 @Override
306 public InputStream getUnicodeStream(final int columnIndex) throws SQLFeatureNotSupportedException {
307 throw new SQLFeatureNotSupportedException("getUnicodeStream(int) not supported");
308 }
309
310 @Override
311 public InputStream getBinaryStream(final int columnIndex) throws SQLException {
312 final Blob blob = getBlob(columnIndex);
313 if (blob == null) {
314 return null;
315 }
316 return blob.getBinaryStream();
317 }
318
319
320
321 @Override
322 public String getString(final String columnLabel) throws SQLException {
323 return getString(findColumn(columnLabel));
324 }
325
326 @Override
327 public boolean getBoolean(final String columnLabel) throws SQLException {
328 return getBoolean(findColumn(columnLabel));
329 }
330
331 @Override
332 public byte getByte(final String columnLabel) throws SQLException {
333 return getByte(findColumn(columnLabel));
334 }
335
336 @Override
337 public short getShort(final String columnLabel) throws SQLException {
338 return getShort(findColumn(columnLabel));
339 }
340
341 @Override
342 public int getInt(final String columnLabel) throws SQLException {
343 return getInt(findColumn(columnLabel));
344 }
345
346 @Override
347 public long getLong(final String columnLabel) throws SQLException {
348 return getLong(findColumn(columnLabel));
349 }
350
351 @Override
352 public float getFloat(final String columnLabel) throws SQLException {
353 return getFloat(findColumn(columnLabel));
354 }
355
356 @Override
357 public double getDouble(final String columnLabel) throws SQLException {
358 return getDouble(findColumn(columnLabel));
359 }
360
361
362
363
364
365 @SuppressWarnings("deprecation")
366 @Override
367 public BigDecimal getBigDecimal(final String columnLabel, final int scale) throws SQLException {
368 return getBigDecimal(findColumn(columnLabel), scale);
369 }
370
371 @Override
372 public byte[] getBytes(final String columnLabel) throws SQLException {
373 return getBytes(findColumn(columnLabel));
374 }
375
376 @Override
377 public Date getDate(final String columnLabel) throws SQLException {
378 return getDate(findColumn(columnLabel));
379 }
380
381 @Override
382 public Time getTime(final String columnLabel) throws SQLException {
383 return getTime(findColumn(columnLabel));
384 }
385
386 @Override
387 public Timestamp getTimestamp(final String columnLabel) throws SQLException {
388 return getTimestamp(findColumn(columnLabel));
389 }
390
391 @Override
392 public InputStream getAsciiStream(final String columnLabel) throws SQLException {
393 return getAsciiStream(findColumn(columnLabel));
394 }
395
396
397
398
399
400 @SuppressWarnings("deprecation")
401 @Override
402 public InputStream getUnicodeStream(final String columnLabel) throws SQLException {
403 return getUnicodeStream(findColumn(columnLabel));
404 }
405
406 @Override
407 public InputStream getBinaryStream(final String columnLabel) throws SQLException {
408 return getBinaryStream(findColumn(columnLabel));
409 }
410
411
412
413
414
415
416
417 @Override
418 public SQLWarning getWarnings() throws SQLException {
419 ensureOpen();
420 return null;
421 }
422
423 @Override
424 public void clearWarnings() throws SQLException {
425 ensureOpen();
426 }
427
428
429
430
431
432
433
434 @Override
435 public String getCursorName() throws SQLFeatureNotSupportedException {
436 throw new SQLFeatureNotSupportedException("getCursorName() not supported");
437 }
438
439 @Override
440 public CsvResultSetMetaData getMetaData() throws SQLException {
441 ensureOpen();
442 return meta;
443 }
444
445
446
447 @Override
448 public Object getObject(final int columnIndex) throws SQLException {
449 return getString(columnIndex);
450 }
451
452 @Override
453 public Object getObject(final String columnLabel) throws SQLException {
454 return getObject(findColumn(columnLabel));
455 }
456
457 @Override
458 public int findColumn(final String columnLabel) throws SQLException {
459 ensureOpen();
460 if (columnLabel != null) {
461 final int max = meta.getColumnCount();
462 for (int i = 1; i <= max; i++) {
463 if (columnLabel.equalsIgnoreCase(meta.getColumnName(i))) {
464 return i;
465 }
466 }
467 }
468 throw new SQLException("invalid column label " + columnLabel);
469 }
470
471 @Override
472 public Reader getCharacterStream(final int columnIndex) throws SQLException {
473 final String s = getString(columnIndex);
474 if (s == null) {
475 return null;
476 }
477 return new StringReader(s);
478 }
479
480 @Override
481 public Reader getCharacterStream(final String columnLabel) throws SQLException {
482 return getCharacterStream(findColumn(columnLabel));
483 }
484
485 @Override
486 public BigDecimal getBigDecimal(final int columnIndex) throws SQLException {
487 return new BigDecimal(getString(columnIndex));
488 }
489
490 @Override
491 public BigDecimal getBigDecimal(final String columnLabel) throws SQLException {
492 return getBigDecimal(findColumn(columnLabel));
493 }
494
495
496
497
498
499
500
501 @Override
502 public boolean isBeforeFirst() throws SQLFeatureNotSupportedException {
503 throw new SQLFeatureNotSupportedException("isBeforeFirst() not supported");
504 }
505
506
507
508
509
510 @Override
511 public boolean isAfterLast() throws SQLFeatureNotSupportedException {
512 throw new SQLFeatureNotSupportedException("isAfterLast() not supported");
513 }
514
515
516
517
518
519 @Override
520 public boolean isFirst() throws SQLFeatureNotSupportedException {
521 throw new SQLFeatureNotSupportedException("isFirst() not supported");
522 }
523
524
525
526
527
528 @Override
529 public boolean isLast() throws SQLFeatureNotSupportedException {
530 throw new SQLFeatureNotSupportedException("isLast() not supported");
531 }
532
533
534
535
536
537 @Override
538 public void beforeFirst() throws SQLFeatureNotSupportedException {
539 throw new SQLFeatureNotSupportedException("beforeFirst() not supported");
540 }
541
542
543
544
545
546 @Override
547 public void afterLast() throws SQLFeatureNotSupportedException {
548 throw new SQLFeatureNotSupportedException("afterLast() not supported");
549 }
550
551
552
553
554
555 @Override
556 public boolean first() throws SQLFeatureNotSupportedException {
557 throw new SQLFeatureNotSupportedException("first() not supported");
558 }
559
560
561
562
563
564 @Override
565 public boolean last() throws SQLFeatureNotSupportedException {
566 throw new SQLFeatureNotSupportedException("last() not supported");
567 }
568
569 @Override
570 public int getRow() throws SQLException {
571 ensureOpen();
572 return rowNumber;
573 }
574
575
576
577
578
579 @Override
580 public boolean absolute(final int row) throws SQLFeatureNotSupportedException {
581 throw new SQLFeatureNotSupportedException("absolute(int) not supported");
582 }
583
584
585
586
587
588 @Override
589 public boolean relative(final int rows) throws SQLFeatureNotSupportedException {
590 throw new SQLFeatureNotSupportedException("relative(int) not supported");
591 }
592
593
594
595
596
597 @Override
598 public boolean previous() throws SQLFeatureNotSupportedException {
599 throw new SQLFeatureNotSupportedException("previous() not supported");
600 }
601
602
603
604
605
606 @Override
607 public void setFetchDirection(final int direction) throws SQLFeatureNotSupportedException {
608 throw new SQLFeatureNotSupportedException("setFetchDirection(int) not supported");
609 }
610
611
612
613
614
615 @Override
616 public int getFetchDirection() throws SQLException {
617 ensureOpen();
618 return ResultSet.FETCH_FORWARD;
619 }
620
621
622
623
624
625 @Override
626 public void setFetchSize(final int rows) throws SQLFeatureNotSupportedException {
627 throw new SQLFeatureNotSupportedException("setFetchSize(int) not supported");
628 }
629
630
631
632
633
634 @Override
635 public int getFetchSize() throws SQLException {
636 ensureOpen();
637 return 0;
638 }
639
640
641
642
643
644 @Override
645 public int getType() throws SQLException {
646 ensureOpen();
647 return ResultSet.TYPE_FORWARD_ONLY;
648 }
649
650
651
652
653
654 @Override
655 public int getConcurrency() throws SQLException {
656 ensureOpen();
657 return ResultSet.CONCUR_READ_ONLY;
658 }
659
660
661
662
663
664 @Override
665 public boolean rowUpdated() throws SQLFeatureNotSupportedException {
666 throw new SQLFeatureNotSupportedException("rowUpdated() not supported");
667 }
668
669
670
671
672
673 @Override
674 public boolean rowInserted() throws SQLFeatureNotSupportedException {
675 throw new SQLFeatureNotSupportedException("rowInserted() not supported");
676 }
677
678
679
680
681
682 @Override
683 public boolean rowDeleted() throws SQLFeatureNotSupportedException {
684 throw new SQLFeatureNotSupportedException("rowDeleted() not supported");
685 }
686
687
688
689
690
691
692
693
694 @Override
695 public void updateNull(final int columnIndex) throws SQLFeatureNotSupportedException {
696 throw new SQLFeatureNotSupportedException("updateNull(int) not supported");
697 }
698
699
700
701
702
703 @Override
704 public void updateBoolean(final int columnIndex, final boolean x) throws SQLFeatureNotSupportedException {
705 throw new SQLFeatureNotSupportedException("updateBoolean(int, boolean) not supported");
706 }
707
708
709
710
711
712 @Override
713 public void updateByte(final int columnIndex, final byte x) throws SQLFeatureNotSupportedException {
714 throw new SQLFeatureNotSupportedException("updateByte(int, byte) not supported");
715 }
716
717
718
719
720
721 @Override
722 public void updateShort(final int columnIndex, final short x) throws SQLFeatureNotSupportedException {
723 throw new SQLFeatureNotSupportedException("updateShort(int, short) not supported");
724 }
725
726
727
728
729
730 @Override
731 public void updateInt(final int columnIndex, final int x) throws SQLFeatureNotSupportedException {
732 throw new SQLFeatureNotSupportedException("updateInt(int, int) not supported");
733 }
734
735
736
737
738
739 @Override
740 public void updateLong(final int columnIndex, final long x) throws SQLFeatureNotSupportedException {
741 throw new SQLFeatureNotSupportedException("updateLong(int, long) not supported");
742 }
743
744
745
746
747
748 @Override
749 public void updateFloat(final int columnIndex, final float x) throws SQLFeatureNotSupportedException {
750 throw new SQLFeatureNotSupportedException("updateFloat(int, float) not supported");
751 }
752
753
754
755
756
757 @Override
758 public void updateDouble(final int columnIndex, final double x) throws SQLFeatureNotSupportedException {
759 throw new SQLFeatureNotSupportedException("updateDouble(int, double) not supported");
760 }
761
762
763
764
765
766 @Override
767 public void updateBigDecimal(final int columnIndex, final BigDecimal x) throws SQLFeatureNotSupportedException {
768 throw new SQLFeatureNotSupportedException("updateBigDecimal(int, BigDecimal) not supported");
769 }
770
771
772
773
774
775 @Override
776 public void updateString(final int columnIndex, final String x) throws SQLFeatureNotSupportedException {
777 throw new SQLFeatureNotSupportedException("updateString(int, String) not supported");
778 }
779
780
781
782
783
784 @Override
785 public void updateBytes(final int columnIndex, final byte[] x) throws SQLFeatureNotSupportedException {
786 throw new SQLFeatureNotSupportedException("updateBytes(int, byte[]) not supported");
787 }
788
789
790
791
792
793 @Override
794 public void updateDate(final int columnIndex, final Date x) throws SQLFeatureNotSupportedException {
795 throw new SQLFeatureNotSupportedException("updateDate(int, Date) not supported");
796 }
797
798
799
800
801
802 @Override
803 public void updateTime(final int columnIndex, final Time x) throws SQLFeatureNotSupportedException {
804 throw new SQLFeatureNotSupportedException("updateTime(int, Time) not supported");
805 }
806
807
808
809
810
811 @Override
812 public void updateTimestamp(final int columnIndex, final Timestamp x) throws SQLFeatureNotSupportedException {
813 throw new SQLFeatureNotSupportedException("updateTimestamp(int, Timestamp) not supported");
814 }
815
816
817
818
819
820 @Override
821 public void updateAsciiStream(final int columnIndex, final InputStream x, final int length) throws SQLFeatureNotSupportedException {
822 throw new SQLFeatureNotSupportedException("updateAsciiStream(int, InputStream, int) not supported");
823 }
824
825
826
827
828
829 @Override
830 public void updateBinaryStream(final int columnIndex, final InputStream x, final int length) throws SQLFeatureNotSupportedException {
831 throw new SQLFeatureNotSupportedException("updateBinaryStream(int, InputStream, int) not supported");
832 }
833
834
835
836
837
838 @Override
839 public void updateCharacterStream(final int columnIndex, final Reader x, final int length) throws SQLFeatureNotSupportedException {
840 throw new SQLFeatureNotSupportedException("updateCharacterStream(int, Reader, int) not supported");
841 }
842
843
844
845
846
847 @Override
848 public void updateObject(final int columnIndex, final Object x, final int scaleOrLength) throws SQLFeatureNotSupportedException {
849 throw new SQLFeatureNotSupportedException("updateObject(int, Object, int) not supported");
850 }
851
852
853
854
855
856 @Override
857 public void updateObject(final int columnIndex, final Object x) throws SQLFeatureNotSupportedException {
858 throw new SQLFeatureNotSupportedException("updateObject(int, Object) not supported");
859 }
860
861
862
863
864
865
866
867
868 @Override
869 public void updateNull(final String columnLabel) throws SQLException {
870 updateNull(findColumn(columnLabel));
871 }
872
873
874
875
876
877 @Override
878 public void updateBoolean(final String columnLabel, final boolean x) throws SQLException {
879 updateBoolean(findColumn(columnLabel), x);
880 }
881
882
883
884
885
886 @Override
887 public void updateByte(final String columnLabel, final byte x) throws SQLException {
888 updateByte(findColumn(columnLabel), x);
889 }
890
891
892
893
894
895 @Override
896 public void updateShort(final String columnLabel, final short x) throws SQLException {
897 updateShort(findColumn(columnLabel), x);
898 }
899
900
901
902
903
904 @Override
905 public void updateInt(final String columnLabel, final int x) throws SQLException {
906 updateInt(findColumn(columnLabel), x);
907 }
908
909
910
911
912
913 @Override
914 public void updateLong(final String columnLabel, final long x) throws SQLException {
915 updateLong(findColumn(columnLabel), x);
916 }
917
918
919
920
921
922 @Override
923 public void updateFloat(final String columnLabel, final float x) throws SQLException {
924 updateFloat(findColumn(columnLabel), x);
925 }
926
927
928
929
930
931 @Override
932 public void updateDouble(final String columnLabel, final double x) throws SQLException {
933 updateDouble(findColumn(columnLabel), x);
934 }
935
936
937
938
939
940 @Override
941 public void updateBigDecimal(final String columnLabel, final BigDecimal x) throws SQLException {
942 updateBigDecimal(findColumn(columnLabel), x);
943 }
944
945
946
947
948
949 @Override
950 public void updateString(final String columnLabel, final String x) throws SQLException {
951 updateString(findColumn(columnLabel), x);
952 }
953
954
955
956
957
958 @Override
959 public void updateBytes(final String columnLabel, final byte[] x) throws SQLException {
960 updateBytes(findColumn(columnLabel), x);
961 }
962
963
964
965
966
967 @Override
968 public void updateDate(final String columnLabel, final Date x) throws SQLException {
969 updateDate(findColumn(columnLabel), x);
970 }
971
972
973
974
975
976 @Override
977 public void updateTime(final String columnLabel, final Time x) throws SQLException {
978 updateTime(findColumn(columnLabel), x);
979 }
980
981
982
983
984
985 @Override
986 public void updateTimestamp(final String columnLabel, final Timestamp x) throws SQLException {
987 updateTimestamp(findColumn(columnLabel), x);
988 }
989
990
991
992
993
994 @Override
995 public void updateAsciiStream(final String columnLabel, final InputStream x, final int length) throws SQLException {
996 updateAsciiStream(findColumn(columnLabel), x, length);
997 }
998
999
1000
1001
1002
1003 @Override
1004 public void updateBinaryStream(final String columnLabel, final InputStream x, final int length) throws SQLException {
1005 updateBinaryStream(findColumn(columnLabel), x, length);
1006 }
1007
1008
1009
1010
1011
1012 @Override
1013 public void updateCharacterStream(final String columnLabel, final Reader reader, final int length) throws SQLException {
1014 updateCharacterStream(findColumn(columnLabel), reader, length);
1015 }
1016
1017
1018
1019
1020
1021 @Override
1022 public void updateObject(final String columnLabel, final Object x, final int scaleOrLength) throws SQLException {
1023 updateObject(findColumn(columnLabel), x, scaleOrLength);
1024 }
1025
1026
1027
1028
1029
1030 @Override
1031 public void updateObject(final String columnLabel, final Object x) throws SQLException {
1032 updateObject(findColumn(columnLabel), x);
1033 }
1034
1035
1036
1037
1038
1039
1040
1041 @Override
1042 public void insertRow() throws SQLFeatureNotSupportedException {
1043 throw new SQLFeatureNotSupportedException("insertRow() not supported");
1044 }
1045
1046
1047
1048
1049
1050 @Override
1051 public void updateRow() throws SQLFeatureNotSupportedException {
1052 throw new SQLFeatureNotSupportedException("updateRow() not supported");
1053 }
1054
1055
1056
1057
1058
1059 @Override
1060 public void deleteRow() throws SQLFeatureNotSupportedException {
1061 throw new SQLFeatureNotSupportedException("deleteRow() not supported");
1062 }
1063
1064
1065
1066
1067
1068 @Override
1069 public void refreshRow() throws SQLFeatureNotSupportedException {
1070 throw new SQLFeatureNotSupportedException("refreshRow() not supported");
1071 }
1072
1073
1074
1075
1076
1077 @Override
1078 public void cancelRowUpdates() throws SQLFeatureNotSupportedException {
1079 throw new SQLFeatureNotSupportedException("cancelRowUpdates() not supported");
1080 }
1081
1082
1083
1084
1085
1086 @Override
1087 public void moveToInsertRow() throws SQLFeatureNotSupportedException {
1088 throw new SQLFeatureNotSupportedException("moveToInsertRow() not supported");
1089 }
1090
1091
1092
1093
1094
1095 @Override
1096 public void moveToCurrentRow() throws SQLFeatureNotSupportedException {
1097 throw new SQLFeatureNotSupportedException("moveToCurrentRow() not supported");
1098 }
1099
1100
1101
1102
1103
1104 @Override
1105 public Statement getStatement() throws SQLException {
1106 ensureOpen();
1107 return null;
1108 }
1109
1110
1111
1112
1113
1114
1115
1116 @Override
1117 public Object getObject(final int columnIndex, final Map<String, Class<?>> map) throws SQLFeatureNotSupportedException {
1118 throw new SQLFeatureNotSupportedException("getObject(int, Map) not supported");
1119 }
1120
1121
1122
1123
1124
1125 @Override
1126 public Ref getRef(final int columnIndex) throws SQLFeatureNotSupportedException {
1127 throw new SQLFeatureNotSupportedException("getRef(int) not supported");
1128 }
1129
1130 @Override
1131 public Blob getBlob(final int columnIndex) throws SQLException {
1132 final String s = getString(columnIndex);
1133 if (s == null) {
1134 return null;
1135 }
1136 return new SerialBlob(s.getBytes());
1137 }
1138
1139 @Override
1140 public Clob getClob(final int columnIndex) throws SQLException {
1141 final String s = getString(columnIndex);
1142 if (s == null) {
1143 return null;
1144 }
1145 return new SerialClob(s.toCharArray());
1146 }
1147
1148
1149
1150
1151
1152 @Override
1153 public Array getArray(final int columnIndex) throws SQLFeatureNotSupportedException {
1154 throw new SQLFeatureNotSupportedException("getArray(int) not supported");
1155 }
1156
1157
1158
1159
1160
1161
1162
1163 @Override
1164 public Object getObject(final String columnLabel, final Map<String, Class<?>> map) throws SQLException {
1165 return getObject(findColumn(columnLabel), map);
1166 }
1167
1168
1169
1170
1171
1172 @Override
1173 public Ref getRef(final String columnLabel) throws SQLException {
1174 return getRef(findColumn(columnLabel));
1175 }
1176
1177 @Override
1178 public Blob getBlob(final String columnLabel) throws SQLException {
1179 return getBlob(findColumn(columnLabel));
1180 }
1181
1182 @Override
1183 public Clob getClob(final String columnLabel) throws SQLException {
1184 return getClob(findColumn(columnLabel));
1185 }
1186
1187
1188
1189
1190
1191 @Override
1192 public Array getArray(final String columnLabel) throws SQLException {
1193 return getArray(findColumn(columnLabel));
1194 }
1195
1196
1197
1198 @Override
1199 public Date getDate(final int columnIndex, final Calendar cal) throws SQLException {
1200 final String s = getString(columnIndex);
1201 if (s == null) {
1202 return null;
1203 }
1204 try {
1205 final DateFormat df = DateFormat.getDateInstance();
1206 df.setCalendar(cal);
1207 return new Date(df.parse(s).getTime());
1208 } catch (final ParseException e) {
1209 throw new SQLException(String.format("Bad format for DATE '%s' in column %d.", s, columnIndex), e);
1210 }
1211 }
1212
1213 @Override
1214 public Date getDate(final String columnLabel, final Calendar cal) throws SQLException {
1215 return getDate(findColumn(columnLabel), cal);
1216 }
1217
1218 @Override
1219 public Time getTime(final int columnIndex, final Calendar cal) throws SQLException {
1220 final String s = getString(columnIndex);
1221 if (s == null) {
1222 return null;
1223 }
1224 try {
1225 final DateFormat df = DateFormat.getTimeInstance();
1226 df.setCalendar(cal);
1227 return new Time(df.parse(s).getTime());
1228 } catch (final ParseException e) {
1229 throw new SQLException(String.format("Bad format for TIME '%s' in column %d.", s, columnIndex), e);
1230 }
1231 }
1232
1233 @Override
1234 public Time getTime(final String columnLabel, final Calendar cal) throws SQLException {
1235 return getTime(findColumn(columnLabel), cal);
1236 }
1237
1238 @Override
1239 public Timestamp getTimestamp(final int columnIndex, final Calendar cal) throws SQLException {
1240 final String s = getString(columnIndex);
1241 if (s == null) {
1242 return null;
1243 }
1244 try {
1245 final DateFormat df = DateFormat.getDateTimeInstance();
1246 df.setCalendar(cal);
1247 return new Timestamp(df.parse(s).getTime());
1248 } catch (final ParseException e) {
1249 throw new SQLException(String.format("Bad format for TIMESTAMP '%s' in column %d.", s, columnIndex), e);
1250 }
1251 }
1252
1253 @Override
1254 public Timestamp getTimestamp(final String columnLabel, final Calendar cal) throws SQLException {
1255 return getTimestamp(findColumn(columnLabel), cal);
1256 }
1257
1258
1259
1260 @Override
1261 public URL getURL(final int columnIndex) throws SQLException {
1262 final String s = getString(columnIndex);
1263 if (s == null) {
1264 return null;
1265 }
1266 try {
1267 return new URL(s);
1268 } catch (final MalformedURLException e) {
1269 throw new SQLException(String.format("Bad format for URL '%s' in column %d.", s, columnIndex), e);
1270 }
1271 }
1272
1273 @Override
1274 public URL getURL(final String columnLabel) throws SQLException {
1275 return getURL(findColumn(columnLabel));
1276 }
1277
1278
1279
1280
1281
1282 @Override
1283 public void updateRef(final int columnIndex, final Ref x) throws SQLFeatureNotSupportedException {
1284 throw new SQLFeatureNotSupportedException("updateRef(int, Ref) not supported");
1285 }
1286
1287
1288
1289
1290
1291 @Override
1292 public void updateRef(final String columnLabel, final Ref x) throws SQLException {
1293 updateRef(findColumn(columnLabel), x);
1294 }
1295
1296
1297
1298
1299
1300 @Override
1301 public void updateBlob(final int columnIndex, final Blob x) throws SQLFeatureNotSupportedException {
1302 throw new SQLFeatureNotSupportedException("updateBlob(int, Blob) not supported");
1303 }
1304
1305
1306
1307
1308
1309 @Override
1310 public void updateBlob(final String columnLabel, final Blob x) throws SQLException {
1311 updateBlob(findColumn(columnLabel), x);
1312 }
1313
1314
1315
1316
1317
1318 @Override
1319 public void updateClob(final int columnIndex, final Clob x) throws SQLFeatureNotSupportedException {
1320 throw new SQLFeatureNotSupportedException("updateBlob(int, Clob) not supported");
1321 }
1322
1323
1324
1325
1326
1327 @Override
1328 public void updateClob(final String columnLabel, final Clob x) throws SQLException {
1329 updateClob(findColumn(columnLabel), x);
1330 }
1331
1332
1333
1334
1335
1336 @Override
1337 public void updateArray(final int columnIndex, final Array x) throws SQLFeatureNotSupportedException {
1338 throw new SQLFeatureNotSupportedException("updateArray(int, Array) not supported");
1339 }
1340
1341
1342
1343
1344
1345 @Override
1346 public void updateArray(final String columnLabel, final Array x) throws SQLException {
1347 updateArray(findColumn(columnLabel), x);
1348 }
1349
1350
1351
1352
1353
1354 @Override
1355 public RowId getRowId(final int columnIndex) throws SQLException {
1356 throw new SQLFeatureNotSupportedException("getRowId(int) not supported");
1357 }
1358
1359
1360
1361
1362
1363 @Override
1364 public RowId getRowId(final String columnLabel) throws SQLException {
1365 return getRowId(findColumn(columnLabel));
1366 }
1367
1368
1369
1370
1371
1372 @Override
1373 public void updateRowId(final int columnIndex, final RowId x) throws SQLFeatureNotSupportedException {
1374 throw new SQLFeatureNotSupportedException("updateRowId(int, RowId) not supported");
1375 }
1376
1377
1378
1379
1380
1381 @Override
1382 public void updateRowId(final String columnLabel, final RowId x) throws SQLException {
1383 updateRowId(findColumn(columnLabel), x);
1384 }
1385
1386
1387
1388
1389
1390 @Override
1391 public int getHoldability() throws SQLException {
1392 ensureOpen();
1393 return ResultSet.HOLD_CURSORS_OVER_COMMIT;
1394 }
1395
1396 @Override
1397 public boolean isClosed() {
1398 return reader == null;
1399 }
1400
1401
1402
1403
1404
1405 @Override
1406 public void updateNString(final int columnIndex, final String string) throws SQLFeatureNotSupportedException {
1407 throw new SQLFeatureNotSupportedException("updateNString(int, String) not supported");
1408 }
1409
1410
1411
1412
1413
1414 @Override
1415 public void updateNString(final String columnLabel, final String string) throws SQLException {
1416 updateNString(findColumn(columnLabel), string);
1417 }
1418
1419
1420
1421
1422
1423 @Override
1424 public void updateNClob(final int columnIndex, final NClob clob) throws SQLFeatureNotSupportedException {
1425 throw new SQLFeatureNotSupportedException("updateNClob(int, NClob) not supported");
1426 }
1427
1428
1429
1430
1431
1432 @Override
1433 public void updateNClob(final String columnLabel, final NClob clob) throws SQLException {
1434 updateNClob(findColumn(columnLabel), clob);
1435 }
1436
1437
1438
1439
1440
1441 @Override
1442 public NClob getNClob(final int columnIndex) throws SQLException {
1443 throw new SQLFeatureNotSupportedException("getNClob(int) not supported");
1444 }
1445
1446
1447
1448
1449
1450 @Override
1451 public NClob getNClob(final String columnLabel) throws SQLException {
1452 return getNClob(findColumn(columnLabel));
1453 }
1454
1455
1456
1457
1458
1459 @Override
1460 public SQLXML getSQLXML(final int columnIndex) throws SQLException {
1461 throw new SQLFeatureNotSupportedException("getSQLXML(int) not supported");
1462 }
1463
1464
1465
1466
1467
1468 @Override
1469 public SQLXML getSQLXML(final String columnLabel) throws SQLException {
1470 return getSQLXML(findColumn(columnLabel));
1471 }
1472
1473
1474
1475
1476
1477 @Override
1478 public void updateSQLXML(final int columnIndex, final SQLXML xmlObject) throws SQLFeatureNotSupportedException {
1479 throw new SQLFeatureNotSupportedException("updateSQLXML(int, SQLXML) not supported");
1480 }
1481
1482
1483
1484
1485
1486 @Override
1487 public void updateSQLXML(final String columnLabel, final SQLXML xmlObject) throws SQLException {
1488 updateSQLXML(findColumn(columnLabel), xmlObject);
1489 }
1490
1491 @Override
1492 public String getNString(final int columnIndex) throws SQLException {
1493 return getString(columnIndex);
1494 }
1495
1496 @Override
1497 public String getNString(final String columnLabel) throws SQLException {
1498 return getNString(findColumn(columnLabel));
1499 }
1500
1501 @Override
1502 public Reader getNCharacterStream(final int columnIndex) throws SQLException {
1503 return getCharacterStream(columnIndex);
1504 }
1505
1506 @Override
1507 public Reader getNCharacterStream(final String columnLabel) throws SQLException {
1508 return getNCharacterStream(findColumn(columnLabel));
1509 }
1510
1511
1512
1513
1514
1515 @Override
1516 public void updateNCharacterStream(final int columnIndex, final Reader x, final long length) throws SQLFeatureNotSupportedException {
1517 throw new SQLFeatureNotSupportedException("updateNCharacterStream(int, Reader, long) not supported");
1518 }
1519
1520
1521
1522
1523
1524 @Override
1525 public void updateNCharacterStream(final String columnLabel, final Reader reader, final long length) throws SQLException {
1526 updateNCharacterStream(findColumn(columnLabel), reader, length);
1527 }
1528
1529
1530
1531
1532
1533 @Override
1534 public void updateAsciiStream(final int columnIndex, final InputStream x, final long length) throws SQLFeatureNotSupportedException {
1535 throw new SQLFeatureNotSupportedException("updateAsciiStream(int, InputStream, long) not supported");
1536 }
1537
1538
1539
1540
1541
1542 @Override
1543 public void updateBinaryStream(final int columnIndex, final InputStream x, final long length) throws SQLFeatureNotSupportedException {
1544 throw new SQLFeatureNotSupportedException("updateBinaryStream(int, InputStream, long) not supported");
1545 }
1546
1547
1548
1549
1550
1551 @Override
1552 public void updateCharacterStream(final int columnIndex, final Reader x, final long length) throws SQLFeatureNotSupportedException {
1553 throw new SQLFeatureNotSupportedException("updateCharacterStream(int, Reader, long) not supported");
1554 }
1555
1556
1557
1558
1559
1560 @Override
1561 public void updateAsciiStream(final String columnLabel, final InputStream x, final long length) throws SQLException {
1562 updateAsciiStream(findColumn(columnLabel), x, length);
1563 }
1564
1565
1566
1567
1568
1569 @Override
1570 public void updateBinaryStream(final String columnLabel, final InputStream x, final long length) throws SQLException {
1571 updateBinaryStream(findColumn(columnLabel), x, length);
1572 }
1573
1574
1575
1576
1577
1578 @Override
1579 public void updateCharacterStream(final String columnLabel, final Reader reader, final long length) throws SQLException {
1580 updateCharacterStream(findColumn(columnLabel), reader, length);
1581 }
1582
1583
1584
1585
1586
1587 @Override
1588 public void updateBlob(final int columnIndex, final InputStream inputStream, final long length) throws SQLFeatureNotSupportedException {
1589 throw new SQLFeatureNotSupportedException("updateBlob(int, InputStream, long) not supported");
1590 }
1591
1592
1593
1594
1595
1596 @Override
1597 public void updateBlob(final String columnLabel, final InputStream inputStream, final long length) throws SQLException {
1598 updateBlob(findColumn(columnLabel), inputStream, length);
1599 }
1600
1601
1602
1603
1604
1605 @Override
1606 public void updateClob(final int columnIndex, final Reader reader, final long length) throws SQLFeatureNotSupportedException {
1607 throw new SQLFeatureNotSupportedException("updateClob(int, Reader, long) not supported");
1608 }
1609
1610
1611
1612
1613
1614 @Override
1615 public void updateClob(final String columnLabel, final Reader reader, final long length) throws SQLException {
1616 updateClob(findColumn(columnLabel), reader, length);
1617 }
1618
1619
1620
1621
1622
1623 @Override
1624 public void updateNClob(final int columnIndex, final Reader reader, final long length) throws SQLFeatureNotSupportedException {
1625 throw new SQLFeatureNotSupportedException("updateNClob(int, Reader, long) not supported");
1626 }
1627
1628
1629
1630
1631
1632 @Override
1633 public void updateNClob(final String columnLabel, final Reader reader, final long length) throws SQLException {
1634 updateNClob(findColumn(columnLabel), reader, length);
1635 }
1636
1637
1638
1639
1640
1641 @Override
1642 public void updateNCharacterStream(final int columnIndex, final Reader x) throws SQLFeatureNotSupportedException {
1643 throw new SQLFeatureNotSupportedException("updateNCharacterStream(int, Reader) not supported");
1644 }
1645
1646
1647
1648
1649
1650 @Override
1651 public void updateNCharacterStream(final String columnLabel, final Reader reader) throws SQLException {
1652 updateNCharacterStream(findColumn(columnLabel), reader);
1653 }
1654
1655
1656
1657
1658
1659 @Override
1660 public void updateAsciiStream(final int columnIndex, final InputStream x) throws SQLFeatureNotSupportedException {
1661 throw new SQLFeatureNotSupportedException("updateAsciiStream(int, InputStream) not supported");
1662 }
1663
1664
1665
1666
1667
1668 @Override
1669 public void updateBinaryStream(final int columnIndex, final InputStream x) throws SQLFeatureNotSupportedException {
1670 throw new SQLFeatureNotSupportedException("updateBinaryStream(int, InputStream) not supported");
1671 }
1672
1673
1674
1675
1676
1677 @Override
1678 public void updateCharacterStream(final int columnIndex, final Reader x) throws SQLFeatureNotSupportedException {
1679 throw new SQLFeatureNotSupportedException("updateCharacterStream(int, Reader) not supported");
1680 }
1681
1682
1683
1684
1685
1686 @Override
1687 public void updateAsciiStream(final String columnLabel, final InputStream x) throws SQLException {
1688 updateAsciiStream(findColumn(columnLabel), x);
1689 }
1690
1691
1692
1693
1694
1695 @Override
1696 public void updateBinaryStream(final String columnLabel, final InputStream x) throws SQLException {
1697 updateBinaryStream(findColumn(columnLabel), x);
1698 }
1699
1700
1701
1702
1703
1704 @Override
1705 public void updateCharacterStream(final String columnLabel, final Reader reader) throws SQLException {
1706 updateCharacterStream(findColumn(columnLabel), reader);
1707 }
1708
1709
1710
1711
1712
1713 @Override
1714 public void updateBlob(final int columnIndex, final InputStream inputStream) throws SQLFeatureNotSupportedException {
1715 throw new SQLFeatureNotSupportedException("updateBlob(int, InputStream) not supported");
1716 }
1717
1718
1719
1720
1721
1722 @Override
1723 public void updateBlob(final String columnLabel, final InputStream inputStream) throws SQLException {
1724 updateBlob(findColumn(columnLabel), inputStream);
1725 }
1726
1727
1728
1729
1730
1731 @Override
1732 public void updateClob(final int columnIndex, final Reader reader) throws SQLFeatureNotSupportedException {
1733 throw new SQLFeatureNotSupportedException("updateClob(int, Reader) not supported");
1734 }
1735
1736
1737
1738
1739
1740 @Override
1741 public void updateClob(final String columnLabel, final Reader reader) throws SQLException {
1742 updateClob(findColumn(columnLabel), reader);
1743 }
1744
1745
1746
1747
1748
1749 @Override
1750 public void updateNClob(final int columnIndex, final Reader reader) throws SQLFeatureNotSupportedException {
1751 throw new SQLFeatureNotSupportedException("updateNClob(int, Reader) not supported");
1752 }
1753
1754
1755
1756
1757
1758 @Override
1759 public void updateNClob(final String columnLabel, final Reader reader) throws SQLException {
1760 updateNClob(findColumn(columnLabel), reader);
1761 }
1762
1763
1764
1765
1766
1767
1768
1769 @Override
1770 public <T> T unwrap(final Class<T> iface) throws SQLFeatureNotSupportedException {
1771 throw new SQLFeatureNotSupportedException("unwrap(Class) not supported");
1772 }
1773
1774
1775
1776
1777
1778 @Override
1779 public boolean isWrapperFor(final Class<?> iface) throws SQLFeatureNotSupportedException {
1780 throw new SQLFeatureNotSupportedException("isWrapperFor(Class) not supported");
1781 }
1782
1783 }