File: ParameterMappingTest.java

package info (click to toggle)
derby 10.14.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 78,896 kB
  • sloc: java: 691,930; sql: 42,686; xml: 20,511; sh: 3,373; sed: 96; makefile: 60
file content (5472 lines) | stat: -rw-r--r-- 190,418 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
/**
 *
 * Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.ParameterMappingTest
 *
 * 
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.derbyTesting.functionTests.tests.jdbcapi;

import java.io.IOException;

import java.io.CharArrayReader;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.Arrays;
import java.util.HashSet;
import java.math.RoundingMode;

import junit.framework.Test;

import org.apache.derbyTesting.junit.BigDecimalHandler;
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
import org.apache.derbyTesting.junit.JDBC;
import org.apache.derbyTesting.junit.TestConfiguration;

import org.apache.derby.iapi.types.HarmonySerialBlob;
import org.apache.derby.iapi.types.HarmonySerialClob;

import org.apache.derbyTesting.functionTests.util.streams.CharAlphabet;
import org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader;

/**
 * 
 */
public class ParameterMappingTest extends BaseJDBCTestCase {
    /** We support BigDecimal if we're <em>not</em> running under JSR 169. */
    private static final boolean HAVE_BIG_DECIMAL = !JDBC.vmSupportsJSR169();

    private static final String BAD_TYPE = "42962";
    private static final String UTF8 = "UTF-8";
    private static final long BIG_INTEGER_SEED = 98L;
    private static final long DATE_SEED = 50L;
    private static final long CALENDAR_SEED = 60L;
    private static final String DATE_METHOD_NAME = "setObject(java.util.Date)";
    private static final String CALENDAR_METHOD_NAME = "setObject(java.util.Calendar)";

    private static  final   String  WONT_FIT = "22003";
    private static  final   String  TRUNCATED = "22001";
        
    private static int[] jdbcTypes = { Types.TINYINT, Types.SMALLINT,
            Types.INTEGER, Types.BIGINT, Types.REAL, Types.FLOAT, Types.DOUBLE,
            Types.DECIMAL, Types.NUMERIC, Types.BIT, Types.BOOLEAN,
            Types.CHAR, Types.VARCHAR, Types.LONGVARCHAR, Types.NULL, // Types.BINARY,
            Types.VARBINARY, Types.NULL, // Types.LONGVARBINARY,
            Types.DATE, Types.TIME, Types.TIMESTAMP, Types.CLOB, Types.BLOB, };

    private static String[] SQLTypes = { null, "SMALLINT", "INTEGER", "BIGINT",
            "REAL", "FLOAT", "DOUBLE", "DECIMAL(10,5)", null, null, "BOOLEAN",
            "CHAR(60)", "VARCHAR(60)", "LONG VARCHAR", "CHAR(60) FOR BIT DATA",
            "VARCHAR(60) FOR BIT DATA", "LONG VARCHAR FOR BIT DATA", "DATE",
            "TIME", "TIMESTAMP", "CLOB(1k)", "BLOB(1k)",

    };

    private static String[] validString = {null,"98","98","98",
           "98","98", "98","98",null,null,"TRUE",
           "98","98","98","0x4",
           "0x4","0x4", "2004-02-14",
           "00:00:00","2004-02-14 00:00:00","98","0x4"};
    
    private static Class[] B3_GET_OBJECT;

    static {
        if (HAVE_BIG_DECIMAL) {
            B3_GET_OBJECT = new Class[] { java.lang.Integer.class, // Types.TINYINT,
                    java.lang.Integer.class, // Types.SMALLINT,
                    java.lang.Integer.class, // Types.INTEGER,
                    java.lang.Long.class, // Types.BIGINT,
                    java.lang.Float.class, // Types.REAL,
                    java.lang.Double.class, // Types.FLOAT,
                    java.lang.Double.class, // Types.DOUBLE,
                    java.math.BigDecimal.class, // Types.DECIMAL,
                    java.math.BigDecimal.class, // Types.NUMERIC,
                    java.lang.Boolean.class, // Types.BIT,
                    java.lang.Boolean.class, // Types.BOOLEAN
                    java.lang.String.class, // Types.CHAR,
                    java.lang.String.class, // Types.VARCHAR,
                    java.lang.String.class, // Types.LONGVARCHAR,
                    byte[].class, // Types.NULL, //Types.BINARY,
                    byte[].class, // Types.VARBINARY,
                    byte[].class, // Types.LONGVARBINARY,
                    java.sql.Date.class, // Types.DATE,
                    java.sql.Time.class, // Types.TIME,
                    java.sql.Timestamp.class, // Types.TIMESTAMP,
                    java.sql.Clob.class, // Types.CLOB,
                    java.sql.Blob.class, // Types.BLOB,
            };
        } else {
            B3_GET_OBJECT = new Class[] { java.lang.Integer.class, // Types.TINYINT,
                    java.lang.Integer.class, // Types.SMALLINT,
                    java.lang.Integer.class, // Types.INTEGER,
                    java.lang.Long.class, // Types.BIGINT,
                    java.lang.Float.class, // Types.REAL,
                    java.lang.Double.class, // Types.FLOAT,
                    java.lang.Double.class, // Types.DOUBLE,
                    java.lang.String.class, // Types.DECIMAL,
                    java.lang.String.class, // Types.NUMERIC,
                    java.lang.Boolean.class, // Types.BIT,
                    java.lang.Boolean.class, // Types.BOOLEAN
                    java.lang.String.class, // Types.CHAR,
                    java.lang.String.class, // Types.VARCHAR,
                    java.lang.String.class, // Types.LONGVARCHAR,
                    byte[].class, // Types.NULL, //Types.BINARY,
                    byte[].class, // Types.VARBINARY,
                    byte[].class, // Types.LONGVARBINARY,
                    java.sql.Date.class, // Types.DATE,
                    java.sql.Time.class, // Types.TIME,
                    java.sql.Timestamp.class, // Types.TIMESTAMP,
                    java.sql.Clob.class, // Types.CLOB,
                    java.sql.Blob.class, // Types.BLOB,
            };
        }
    }

    private static final boolean n = false;

    private static final boolean X = true;

        /**
                JDBC 3.0 spec Table B6 - Use of ResultSet getter Methods to Retrieve JDBC Data Types
        */
        public static final boolean[][] B6 = {

// Types.             T  S  I  B  R  F  D  D  N  B  B  C  V  L  B  V  L  D  T  T  C  B
//                    I  M  N  I  E  L  O  E  U  I  O  H  A  O  I  A  O  A  I  I  L  L
//                    N  A  T  G  A  O  U  C  M  T  O  A  R  N  N  R  N  T  M  M  O  O
//                    Y  L  E  I  L  A  B  I  E     L  R  C  G  A  B  G  E  E  E  B  B
//                    I  L  G  N     T  L  M  R     E     H  V  R  I  V        S
//                    N  I  E  T        E  A  I     A     A  A  Y  N  A        T
//                    T  N  R              L  C     N     R  R     A  R        A
//                    T                                      C     R  B        M
//                                                           H     B  I        P
//                                                           A     I  N
//                                                           R     N  

/* 0 getByte*/          { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 1 getShort*/         { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 2 getInt*/           { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 3 getLong*/          { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 4 getFloat*/         { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 5 getDouble*/        { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 6 getBigDecimal*/    { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 7 getBoolean*/       { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 8 getString*/        { X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n},
/* 9 getBytes*/         { n, n, n, n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, n, n},
/*10 getDate*/          { n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, X, n, X, n, n},
/*11 getTime*/          { n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, n, X, X, n, n},
/*12 getTimestamp*/     { n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, X, X, X, n, n},
/*13 getAsciiStream*/   { n, n, n, n, n, n, n, n, n, n, n, X, X, X, X, X, X, n, n, n, n, n},
/*14 getBinaryStream*/  { n, n, n, n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, n, n},
/*15 getCharStream*/    { n, n, n, n, n, n, n, n, n, n, n, X, X, X, X, X, X, n, n, n, n, n},
/*16 getClob */         { n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, X, n},
/*17 getBlob */         { n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, X},
                 
/*18 getUnicodeStream */{ n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n},
        };


        /**
                JDBC 3.0 Section 13.2.2.1 specifies that table B-2 is used to specify type mappings
                from the Java types (e.g. int as setInt) to the JDBC SQL Type (Types.INT).

                This table does not include stream methods and does not include conversions
                specified elsewhere in the text, Namely

                Section 16.3.2
                        setBinaryStream may be used to set a BLOB
                        setAsciiStream and setCharacterStream may be used to set a CLOB

                Thus this B2_MOD table is laid out like the B6 table and makes
                the assumptions that

                - Any Java numeric type can be used to set any SQL numeric type
                - Any Java numeric type can be used to set any SQL CHAR type
                - Numeric and date/time java types can be converted to SQL Char values.

                
        */

        // Types.             T  S  I  B  R  F  D  D  N  B  B  C  V  L  B  V  L  D  T  T  C  B
        //                    I  M  N  I  E  L  O  E  U  I  O  H  A  O  I  A  O  A  I  I  L  L
        //                    N  A  T  G  A  O  U  C  M  T  O  A  R  N  N  R  N  T  M  M  O  O
        //                    Y  L  E  I  L  A  B  I  E     L  R  C  G  A  B  G  E  E  E  B  B
        //                    I  L  G  N     T  L  M  R     E     H  V  R  I  V        S
        //                    N  I  E  T        E  A  I     A     A  A  Y  N  A        T
        //                    T  N  R              L  C     N     R  R     A  R        A
        //                       T                                   C     R  B        M
        //                                                           H     B  I        P
        //                                                           A     I  N
        //                                                           R     N  

        public static boolean[][] B2_MOD = {
/* 0 setByte*/          { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 1 setShort*/         { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 2 setInt*/           { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 3 setLong*/          { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 4 setFloat*/         { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 5 setDouble*/        { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 6 setBigDecimal*/    { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 7 setBoolean*/       { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 8 setString*/        { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, X, X, X, n, n},
/* 9 setBytes*/         { n, n, n, n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, n, n},
/*10 setDate*/          { n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, X, n, X, n, n},
/*11 setTime*/          { n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, n, X, n, n, n},
/*12 setTimestamp*/     { n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, X, X, X, n, n},
/*13 setAsciiStream*/   { n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, n, n, n, X, n},
/*14 setBinaryStream*/  { n, n, n, n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, n, X},
/*15 setCharStream*/    { n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, n, n, n, X, n},
/*16 setClob */         { n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, X, n},
/*17 setBlob */         { n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, X},
                 
/*18 setUnicodeStream */{ n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n},
        };

        /** Table B5 conversion of Objects using setObject*/

// Types.             T  S  I  B  R  F  D  D  N  B  B  C  V  L  B  V  L  D  T  T  C  B
//                    I  M  N  I  E  L  O  E  U  I  O  H  A  O  I  A  O  A  I  I  L  L
//                    N  A  T  G  A  O  U  C  M  T  O  A  R  N  N  R  N  T  M  M  O  O
//                    Y  L  E  I  L  A  B  I  E     L  R  C  G  A  B  G  E  E  E  B  B
//                    I  L  G  N     T  L  M  R     E     H  V  R  I  V        S
//                    N  I  E  T        E  A  I     A     A  A  Y  N  A        T
//                    T  N  R              L  C     N     R  R     A  R        A
//                    T                                      C     R  B        M
//                                                           H     B  I        P
//                                                           A     I  N
//                                                           R     N  
        public static boolean[][] B5 = {
/* 0 String */          { X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, X, X, X, X, n, n},
/* 1 BigDecimal */      { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 2 Boolean */         { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 3 Integer */         { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 4 Long */            { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 5 Float */           { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 6 Double */          { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/* 7 byte[] */          { n, n, n, n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, n, n},
/* 8 Date */            { n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, X, n, X, n, n},
/* 9 Time */            { n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, n, X, n, n, n},
/*10 Timestamp */       { n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, X, X, X, n, n},
/*11 Blob   */          { n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, X},
/*12 Clob */            { n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, X, n},

//Byte and Short were added to this table in JDBC 4.0. (See DERBY-1500.)

/*13 Byte */            { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
/*14 Short */           { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},

//java.math.BigInteger, java.util.Date and java.util.Calendar were added to this table in JDBC 4.1. (See DERBY-5488.)

/*15 java.math.BigInteger */            { n, n, n, X, n, n, n, n, n, n, n, X, X, X, n, n, n, n, n, n, n, n},
/*16 java.util.Date */       { n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, X, X, X, n, n},
/*17 java.util.Calendar */       { n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, X, X, X, n, n},
        };

     
        public static final boolean[][]  allowRegisterOut = {
     

    //          Types.                T  S  I  B  R  F  D  D  N  B  B  C  V  L  B  V  L  D  T  T  C  B
//                                    I  M  N  I  E  L  O  E  U  I  O  H  A  O  I  A  O  A  I  I  L  L
//                                    N  A  T  G  A  O  U  C  M  T  O  A  R  N  N  R  N  T  M  M  O  O
//                                    Y  L  E  I  L  A  B  I  E     L  R  C  G  A  B  G  E  E  E  B  B
//                                    I  L  G  N     T  L  M  R     E     H  V  R  I  V        S
//                                    N  I  E  T        E  A  I     A     A  A  Y  N  A        T
//                                    T  N  R              L  C     N     R  R     A  R        A
//                                       T                                   C     R  B        M
//                                                                           H     B  I        P
//                                                                           A     I  N
//    param sqlType                                                          R     N  
            /* 0 null    */         { n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n},
            /* 1 SMALLINT*/         { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
            /* 2 INTEGER*/          { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
            /* 3 BIGINT */          { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
            /* 4 REAL    */         { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
            /* 5 FLOAT     */       { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
            /* 6 DOUBLE    */       { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
            /* 7 DECIMAL*/          { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
            /* 8 null     */        { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, X, X, X, n, n},
            /* 9 null*/             { n, n, n, n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, n, n},
            /*10 BOOLEAN   */       { X, X, X, X, X, X, X, X, X, X, X, X, X, X, n, n, n, n, n, n, n, n},
            /*11 CHAR(60) */        { n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, n, X, n, n, n},
            /*12 VARCHAR(60) */     { n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, X, X, X, n, n},
            /*13 LONG VARCHAR */    { n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n},
            /*14 CHAR FOR BIT   */  { n, n, n, n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, n, n},
            /*15 VARCHAR FOR BIT*/  { n, n, n, n, n, n, n, n, n, n, n, n, n, n, X, X, X, n, n, n, n, n},
            /*16 LONGVARCHAR FOR B*/{ n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n},
            /*17 DATE */            { n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, X, n, n, n, n},
            /*18 TIME */            { n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, X, n, n, n},
            /*19 TIMESTAMP */       { n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, X, n, n},
            /*20 CLOB         */    { n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n},
            /*21 BLOB         */    { n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n},
                    };

        
            
        
    /**
     * @param arg0
     */
    public ParameterMappingTest(String arg0) {
        super(arg0);
    }

    /*
     * (non-Javadoc)
     * 
     * @see junit.framework.TestCase#setUp()
     */
    protected void setUp() throws Exception {
        Connection conn = getConnection();

        conn.setAutoCommit(false);

        // create simple a table with BLOB and CLOB thta
        // can be used to for setBlob/setClob testing.
        Statement scb = conn.createStatement();

        scb.execute("CREATE TABLE PM.LOB_GET(ID INT, B BLOB, C CLOB)");
        PreparedStatement pscb = conn
                .prepareStatement("INSERT INTO PM.LOB_GET VALUES (?, ?, ?)");
        pscb.setInt(1, 0);
        pscb.setNull(2, Types.BLOB);
        pscb.setNull(3, Types.CLOB);
        pscb.executeUpdate();

        pscb.setInt(1, 1);
        {
            byte[] data = new byte[6];
            data[0] = (byte) 0x4;
            data[1] = (byte) 0x3;
            data[2] = (byte) 0x72;
            data[3] = (byte) 0x43;
            data[4] = (byte) 0x00;
            data[5] = (byte) 0x37;

            pscb.setBinaryStream(2, new java.io.ByteArrayInputStream(data), 6);
        }
        pscb.setCharacterStream(3, new java.io.StringReader("72"), 2);
        pscb.executeUpdate();
        scb.close();
        pscb.close();
        conn.commit();

    }

    public void helperTestDerby6214(int numberOfRowsToUpdate, 
            int testVariation) throws Exception
    {
        // create large (>32k) string to put in the CLOB
        final int size = 53000;
        StringBuilder sb = new StringBuilder(size);
        for (int i = 0; i < size; i += 10) {
            sb.append("1234567890");
        }

        PreparedStatement ps = prepareStatement("UPDATE Test3 SET C16 = ?, " + 
            "I07 = I07 + 1 WHERE S02 IN (?, ?)");

        switch (testVariation) {
        case 1 :
            ps.setString(1, "abc");
            break;
        case 2 :
            //Following fails for client server for stream close error
            // if we are updating more than one row
            ps.setString(1, sb.toString());
            break;
        case 3 :
            //Following fails for client server for stream close error
            // if we are updating more than one row
            ps.setObject(1, "abc", Types.CLOB);
            break;
        case 4 :
            //Following fails for client server for stream close error
            // if we are updating more than one row
            ps.setObject(1, sb.toString(), Types.CLOB);
            break;
        }
        
        //First value in IN clause is getting set to 'AAAAA'
        ps.setObject(2, "AAAAA", Types.VARCHAR);
        if (numberOfRowsToUpdate == 1 ) {
            //Second value in IN clause is also getting set to 'AAAAA', which 
            // means prepared statement will update only one row
            ps.setObject(3, "AAAAA", Types.VARCHAR);
        } else {
            //Second value in IN clause is also getting set to 'EEEEE', which 
            // means prepared statement will update two rows
            ps.setObject(3, "EEEEE", Types.VARCHAR);
        }
        	
        ps.execute();

    }

    /**
     * DERBY-6214 (PreparedStatement.setObject(int, Object, Types.CLOB) 
     * 	 fail with DerbyNet) 
     * Test setObject and setString on CLOB columns 
     * @throws Exception
     */
    public void testDerby6214() throws Exception
    {
        Statement s = createStatement();
        s.executeUpdate("CREATE TABLE Test3 ("+
                "S02 VARCHAR(64) NOT NULL, " +
          	    "I07 INTEGER, " +
                "C16 CLOB)"); 
        s.executeUpdate("INSERT INTO Test3 (S02, I07) " +
                "VALUES ('AAAAA', 1)");
        s.executeUpdate("INSERT INTO Test3 (S02, I07) " +
                "VALUES ('EEEEE', 1)");
        
        for (int i=1; i<3; i++) 
        {
        	for (int j=1; j<5; j++)
        	{
        		//once DERBY-6214 is fixed, we can remove following check
        		if (usingDerbyNetClient() && //we are in network server mode
                        i==2 && //we are going to update 2 rows 
                        (j==2 || //we are using setString to insert large string
                        j == 3 || //we are using setObject
                        j == 4)) //we are using setObject
        		{
        			continue;
        		}
        		helperTestDerby6214(i,j);
        	}
        }
    }
    /**
     * Test setBigDecimal does not lose fractional digits
     * @throws Exception
     */
    public void testDerby2073() throws Exception
    {
        // Cannot use setBigDecimal with J2ME
        if (!JDBC.vmSupportsJDBC3())
            return;
        
        
        Statement s = createStatement();
        s.executeUpdate("CREATE TABLE DERBY_2073_TAB (dc DECIMAL(10,2), db double, r real, i int)");
        PreparedStatement ps = prepareStatement("INSERT INTO DERBY_2073_TAB VALUES(?,?,?,?)");
        BigDecimal value = new BigDecimal("123.45");
        ps.setBigDecimal(1, value);
        ps.setBigDecimal(2, value);
        ps.setBigDecimal(3, value);
        ps.setBigDecimal(4, value);
        ps.executeUpdate();
        // Test with null values as the change sets precision/scale for null values differently
        ps.setBigDecimal(1, null);
        ps.setBigDecimal(2, null);
        ps.setBigDecimal(3, null);
        ps.setBigDecimal(4, null);
        ps.executeUpdate();

        // Can't use negative scale on jdk1.4.2
        if (JDBC.vmSupportsJDBC4())
        {
            // Test with negative scale.
            value = new BigDecimal(new BigInteger("2"), -3);
        }
        else
        {
            value = new BigDecimal("2000");
        }
        ps.setBigDecimal(1,value);
        ps.setBigDecimal(2,value);
        ps.setBigDecimal(3,value);
        ps.setBigDecimal(4,value);
        ps.executeUpdate();        
        
        value = new BigDecimal("123.45");
        // Test with setObject and scale of 2
        ps.setObject(1, value,java.sql.Types.DECIMAL,2);
        ps.setObject(2, value,java.sql.Types.DECIMAL,2);
        ps.setObject(3, value,java.sql.Types.DECIMAL,2);
        ps.setObject(4, value,java.sql.Types.DECIMAL,2);
        ps.executeUpdate();
        
        // Test with setObject and scale of 0
        ps.setObject(1, value,java.sql.Types.DECIMAL,0);
        ps.setObject(2, value,java.sql.Types.DECIMAL,0);
        ps.setObject(3, value,java.sql.Types.DECIMAL,0);
        ps.setObject(4, value,java.sql.Types.DECIMAL,0);
        ps.executeUpdate();
        
        
        // Test with setObject and type with no scale.
        // should default to scale 0
        ps.setObject(1, value,java.sql.Types.DECIMAL);
        ps.setObject(2, value,java.sql.Types.DECIMAL);
        ps.setObject(3, value,java.sql.Types.DECIMAL);
        ps.setObject(4, value,java.sql.Types.DECIMAL);
        ps.executeUpdate();
        
        // Test with setObject and no type and no scale.
        // Keeps the fractional digits.
        ps.setObject(1, value);
        ps.setObject(2, value);
        ps.setObject(3, value);
        ps.setObject(4, value);
        ps.executeUpdate();
        
        // Can't use negative scale on jdk1.4.2
        if (JDBC.vmSupportsJDBC4())
        {
            // Test with setObject and negative scale.
            value = new BigDecimal(new BigInteger("2"), -3);
        } else
        {
            value = new BigDecimal("2000");
        }
        ps.setObject(1,value);
        ps.setObject(2,value);
        ps.setObject(3,value);
        ps.setObject(4,value);
        ps.executeUpdate();
        ResultSet rs = s.executeQuery("SELECT * FROM DERBY_2073_TAB");
        String [][] expectedResults = new String [][]
               {{"123.45","123.45","123.45","123"},
                {null,null,null,null},
                {"2000.00","2000.0","2000.0","2000"},
                {"123.45","123.45","123.45","123"},
                {"123.00","123.0","123.0","123"},
                {"123.00","123.0","123.0","123"},
                {"123.45","123.45","123.45","123"},
                {"2000.00","2000.0","2000.0","2000"}};
                                      
                                                    
       // Cannot run for embedded for now because embedded
       // does not adjust the scale if the  column is 
        // not BigDecimal (e.g. double or real or varchar.) (DERBY-3128)
        if (usingDerbyNetClient())
            JDBC.assertFullResultSet(rs, expectedResults);
           
        
        s.executeUpdate("DROP TABLE DERBY_2073_TAB");
        
    }
    
    public void testParameterMapping() throws Exception {
        Connection conn = getConnection();

        for (int type = 0; type < SQLTypes.length; type++) {

            String sqlType = SQLTypes[type];

            if (sqlType == null || jdbcTypes[type] == Types.NULL) {
                continue;
            }

            Statement s = conn.createStatement();
            try {
                s.execute("DROP TABLE PM.TYPE_AS");
            } catch (SQLException seq) {
            }
            s.execute("CREATE TABLE PM.TYPE_AS(VAL " + SQLTypes[type] + ")");

            PreparedStatement psi = conn
                    .prepareStatement("INSERT INTO PM.TYPE_AS(VAL) VALUES(?)");
            psi.setNull(1, jdbcTypes[type]);
            psi.executeUpdate();

            PreparedStatement psq = conn
                    .prepareStatement("SELECT VAL FROM PM.TYPE_AS");
            ResultSet rs = psq.executeQuery();
            ResultSetMetaData rsmd = rs.getMetaData();
            assertEquivalentDataType(jdbcTypes[type], rsmd.getColumnType(1));
            rs.close();
            // For this data type
            // Test inserting a NULL value and then performing all the getXXX()
            // calls on it.

            // System.out.println(" NULL VALUE");
            getXXX(psq, type, true);

            s.execute("DELETE FROM PM.TYPE_AS");

            // For this data type
            // Test inserting a valid value and then performing all the getXXX()
            // calls on it.
            if (setValidValue(psi, 1, jdbcTypes[type])) {
                psi.executeUpdate();
                getXXX(psq, type, false);
            }
            setXXX(s, psi, psq, type);

            psi.close();
            psq.close();
            s.execute("DROP TABLE PM.TYPE_AS");
            conn.commit();
            //          NOW PROCEDURE PARAMETERS
            try {
                s.execute("DROP PROCEDURE PMP.TYPE_AS");
            }catch (SQLException seq) {
            }
            String procSQL;
            procSQL = "CREATE PROCEDURE PMP.TYPE_AS(" +
                "IN P1 " + SQLTypes[type] + 
                ", INOUT P2 " + SQLTypes[type] +
                ", OUT P3 " + SQLTypes[type] +
                ") LANGUAGE JAVA PARAMETER STYLE JAVA NO SQL " +
                " EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.jdbcapi.ParameterMappingTest.pmap'";
                        
            try {
                if (!HAVE_BIG_DECIMAL && SQLTypes[type].equals("DECIMAL(10,5)"))
                    continue;
                println(procSQL);
                s.execute(procSQL);
            } catch (SQLException sqle) {
                // may get error that column is not allowed
                if (BAD_TYPE.equals(sqle.getSQLState()))
                    continue;
                else
                    fail(sqle.getSQLState() + ":" + sqle.getMessage());
                continue;
            }
            
            // For each JDBC type try to register the out parameters with that type.
                for (int opt = 0; opt < jdbcTypes.length; opt++) {
                    int jopt = jdbcTypes[opt];
                    if (jopt == Types.NULL)
                        continue;

                    CallableStatement csp = conn.prepareCall("CALL PMP.TYPE_AS(?, ?, ?)");
                    
                    boolean bothRegistered = true;
                    //System.out.print("INOUT " + sqlType + " registerOutParameter(" + JDBC.sqlNameFromJdbc(jopt) + ") ");
                    try {
                        csp.registerOutParameter(2, jopt);
                    } catch (SQLException sqle) {
                        assertFalse("INOUT " + sqlType + " registerOutParameter(" + JDBC.sqlNameFromJdbc(jopt) + 
                                ") failed",allowRegisterOut[type][opt]);
                        if (!"XCL25".equals(sqle.getSQLState()))
                            fail("-- " + sqle.getSQLState());
                        bothRegistered = false;
                      }       
                    //System.out.print("OUT " + sqlType + " registerOutParameter(" + TestUtil.getNameFromJdbcType(jopt) + ") ");
                    try {
                        csp.registerOutParameter(3, jopt);
                    } catch (SQLException sqle) {
                        if (!"XCL25".equals(sqle.getSQLState()))
                            fail("-- " + sqle.getSQLState());
                        assertFalse("OUT " + sqlType + " registerOutParameter(" + JDBC.sqlNameFromJdbc(jopt) + 
                                "failed",allowRegisterOut[type][opt]);
                        bothRegistered = false;
                    }

                    if (bothRegistered) {
                        
                        try {

                            // set the IN value with an accepted value according to its type
                            // set the INOUT value with an accepted value according to its registered type
                            if (setValidValue(csp, 1, jdbcTypes[type]) && setValidValue(csp, 2, jopt)) {

                                csp.execute();
                                
                               // now get the INOUT, OUT parameters according to their registered type.
                                getOutValue(csp, 2, jopt,type); 
                                
                                getOutValue(csp, 3, jopt,type);
                        }

                        } catch (SQLException sqle) {
                            boolean expectedConversionError = ("22018".equals(sqle.getSQLState())|| 
                                                               "22007".equals(sqle.getSQLState()) ||
                                                               "22005".equals(sqle.getSQLState()));
                            if ( !expectedConversionError)
                            {
                                printStackTrace( sqle );
                            }
                            assertTrue("FAIL: Unexpected exception" + sqle.getSQLState() + ":" + sqle.getMessage(),
                                    expectedConversionError);
                        }
                    }   

                    csp.close();
                    
                 }      

                
                s.execute("DROP PROCEDURE PMP.TYPE_AS");
                s.close();
                conn.commit();
         }      
    }

    /**
     * Verify correct mapping of clobs.
     */
    public void testClobMapping() throws Exception
    {
        Connection conn = getConnection();
        PreparedStatement ps;
        CallableStatement cs;
        Clob outVal;

        //
        // Clob input parameter
        //
        ps = chattyPrepare
            (
             conn,
             "create procedure clobIn\n" +
             "( in c clob, out result varchar( 100 ) )\n" +
             "language java\n" +
             "parameter style java\n" +
             "no sql\n" +
             "external name '" + getClass().getName() + ".clobIn'\n"
             );
        ps.execute();
        ps.close();

        cs = chattyPrepareCall( conn, "call clobIn( cast( 'def' as clob ), ? )" );
        cs.registerOutParameter( 1, Types.VARCHAR );
        cs.execute();
        assertEquals( "def", cs.getString( 1 ) );
        cs.close();

        cs = chattyPrepareCall( conn, "call clobIn( ?, ? )" );
        cs.setClob( 1, new HarmonySerialClob( "ghi" ) );
        cs.registerOutParameter( 2, Types.VARCHAR );
        cs.execute();
        assertEquals( "ghi", cs.getString( 2 ) );
        cs.close();

        //
        // Clob output parameter
        //
        ps = chattyPrepare
            (
             conn,
             "create procedure clobOut\n" +
             "( out c clob )\n" +
             "language java\n" +
             "parameter style java\n" +
             "no sql\n" +
             "external name '" + getClass().getName() + ".clobOut'\n"
             );
        ps.execute();
        ps.close();
        
        cs = chattyPrepareCall( conn, "call clobOut( ? )" );
        cs.registerOutParameter( 1, Types.CLOB );
        cs.execute();
        outVal = cs.getClob( 1 );
        assertEquals( "abc", outVal.getSubString( 1L, (int) outVal.length() ) );
        cs.close();

        //
        // Clob inout parameter
        //
        ps = chattyPrepare
            (
             conn,
             "create procedure clobInOut\n" +
             "( inout c clob )\n" +
             "language java\n" +
             "parameter style java\n" +
             "no sql\n" +
             "external name '" + getClass().getName() + ".clobInOut'\n"
             );
        ps.execute();
        ps.close();
        
        cs = chattyPrepareCall( conn, "call clobInOut( ? )" );
        cs.setClob( 1, new HarmonySerialClob( "ghi" ) );
        cs.registerOutParameter( 1, Types.CLOB );
        cs.execute();
        outVal = cs.getClob( 1 );
        assertEquals( "ihg", outVal.getSubString( 1L, (int) outVal.length() ) );

        Clob inValue = makeBigClob();
        cs.setClob( 1, inValue );
        cs.execute();
        Clob outValue = cs.getClob( 1 );
        compareClobs( inValue, outValue );
        
        cs.close();
    }
    private Clob makeBigClob() throws Exception
    {
        char[] template = "abcdefghijklmnopqrstuvwxyz".toCharArray();
        int templateLength = template.length;
        int multiplier = 50000;
        char[] value = new char[ templateLength * multiplier ];
        int idx = 0;
        for ( int i = 0; i < multiplier; i++ )
        {
            for ( int j = 0; j < templateLength; j++ )
            {
                value[ idx++ ] = template[ j ];
            }
                          
        }
        
        return new HarmonySerialClob( new String( value ) );
    }
    private void compareClobs( Clob left, Clob right ) throws Exception
    {
        long leftLength = left.length();
        long rightLength = right.length();

        println( "Left clob has " + leftLength + " characters and right clob has " + rightLength + " characters." );

        assertEquals( leftLength, rightLength );

        if ( leftLength == rightLength );
        {
            String leftString = left.getSubString( 1L, (int) leftLength );
            String rightString = right.getSubString( 1L, (int) rightLength );

            for ( int i = 0; i < leftLength; i++ )
            {
                int leftIdx = (int) i;
                int rightIdx = (int) ((leftLength - leftIdx) - 1);
                char leftC = leftString.charAt( leftIdx );
                char rightC = rightString.charAt( rightIdx );

                if ( leftC != rightC )
                {
                    println( "left[ " + leftIdx+ " ] = " + leftC + " but right[ " + rightIdx + " ] = " + rightC );
                    return;
                }

                assertEquals( leftC, rightC );
            }
        }

    }

    /**
     * Verify correct mapping of blobs.
     */
    public void testBlobMapping() throws Exception
    {
        Connection conn = getConnection();
        PreparedStatement ps;
        CallableStatement cs;
        Blob outVal;

        //
        // Blob input parameter
        //
        ps = chattyPrepare
            (
             conn,
             "create procedure blobIn\n" +
             "( in c blob, out result varchar( 100 ) )\n" +
             "language java\n" +
             "parameter style java\n" +
             "no sql\n" +
             "external name '" + getClass().getName() + ".blobIn'\n"
             );
        ps.execute();
        ps.close();

        cs = chattyPrepareCall( conn, "call blobIn( ?, ? )" );
        cs.setBlob( 1, new HarmonySerialBlob( "ghi".getBytes( UTF8 ) ) );
        cs.registerOutParameter( 2, Types.VARCHAR );
        cs.execute();
        assertEquals( "ghi", cs.getString( 2 ) );
        cs.close();

        //
        // Blob output parameter
        //
        ps = chattyPrepare
            (
             conn,
             "create procedure blobOut\n" +
             "( out c blob )\n" +
             "language java\n" +
             "parameter style java\n" +
             "no sql\n" +
             "external name '" + getClass().getName() + ".blobOut'\n"
             );
        ps.execute();
        ps.close();

        cs = chattyPrepareCall( conn, "call blobOut( ? )" );
        cs.registerOutParameter( 1, Types.BLOB );
        cs.execute();
        outVal = cs.getBlob( 1 );
        assertEquals( "abc", getBlobValue( outVal ) );
        cs.close();
        
        //
        // Blob inout parameter
        //
        ps = chattyPrepare
            (
             conn,
             "create procedure blobInOut\n" +
             "( inout c blob )\n" +
             "language java\n" +
             "parameter style java\n" +
             "no sql\n" +
             "external name '" + getClass().getName() + ".blobInOut'\n"
             );
        ps.execute();
        ps.close();

        cs = chattyPrepareCall( conn, "call blobInOut( ? )" );
        cs.setBlob( 1, new HarmonySerialBlob( "ghi".getBytes( UTF8 ) ) );
        cs.registerOutParameter( 1, Types.BLOB );
        cs.execute();
        outVal = cs.getBlob( 1 );
        assertEquals( "ihg", getBlobValue( outVal ) );
        
        Blob inValue = makeBigBlob();
        cs.setBlob( 1, inValue );
        cs.execute();
        Blob outValue = cs.getBlob( 1 );
        compareBlobs( inValue, outValue );

        cs.close();
    }
    private Blob makeBigBlob() throws Exception
    {
        byte[] template = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        int templateLength = template.length;
        int multiplier = 110000;
        byte[] value = new byte[ templateLength * multiplier ];
        int idx = 0;
        for ( int i = 0; i < multiplier; i++ )
        {
            for ( int j = 0; j < templateLength; j++ )
            {
                value[ idx++ ] = template[ j ];
            }
                          
        }
        
        return new HarmonySerialBlob( value );
    }
    private void compareBlobs( Blob left, Blob right ) throws Exception
    {
        long leftLength = left.length();
        long rightLength = right.length();

        println( "Left blob has " + leftLength + " bytes and right blob has " + rightLength + " bytes." );

        assertEquals( leftLength, rightLength );

        if ( leftLength == rightLength );
        {
            byte[] leftBytes = left.getBytes( 1L, (int) leftLength );
            byte[] rightBytes = right.getBytes( 1L, (int) rightLength );

            for ( int i = 0; i < leftLength; i++ )
            {
                int leftIdx = (int) i;
                int rightIdx = (int) ((leftLength - leftIdx) - 1);
                byte leftC = leftBytes[ leftIdx ];
                byte rightC = rightBytes[ rightIdx ];

                if ( leftC != rightC )
                {
                    println( "left[ " + leftIdx+ " ] = " + leftC + " but right[ " + rightIdx + " ] = " + rightC );
                    return;
                }

                assertEquals( leftC, rightC );
            }
        }
    }

    /**
     * Test the new object mappings allowed by setObject() in JDBC 4.1. See
     * DERBY-5488.
     */
    public  void    test_jdbc4_1_objectMappings() throws  Exception
    {
        Connection conn = getConnection();

        Statement s = conn.createStatement();
        try {
            s.execute( "drop table t_object_map" );
        } catch (SQLException seq) {}
        s.execute( "create table t_object_map( a int, b timestamp, c bigint )" );

        PreparedStatement   ps = conn.prepareStatement
            ( "insert into t_object_map( a, b, c ) values ( ?, ?, ? )" );

        // insert objects that are now supported
        ps.setInt( 1, 1 );
        ps.setObject( 2, new java.util.Date( DATE_SEED ) );
        ps.setObject( 3, null );
        ps.executeUpdate();

        ps.setInt( 1, 2 );
        ps.setObject( 2, makeCalendar( CALENDAR_SEED ) );
        ps.setObject( 3, null );
        ps.executeUpdate();

        ps.setInt( 1, 3 );
        ps.setObject( 2, null );
        ps.setObject( 3, new BigInteger( Long.toString( BIG_INTEGER_SEED ) ) );
        ps.executeUpdate();

        ps.close();

        // verify that the correct values were inserted

        ps = conn.prepareStatement( "select * from t_object_map order by a" );
        ResultSet   rs = ps.executeQuery();

        rs.next();
        assertEquals( DATE_SEED, rs.getTimestamp( 2 ).getTime() );

        rs.next();
        assertEquals( CALENDAR_SEED, rs.getTimestamp( 2 ).getTime() );

        rs.next();
        assertEquals( BIG_INTEGER_SEED, rs.getLong( 3 ) );

        rs.close();
        ps.close();
    }
    private static  java.util.Calendar  makeCalendar( long calendarSeed )
    {
        java.util.Calendar calendar = java.util.Calendar.getInstance();
        calendar.setTime( new java.util.Date( calendarSeed ) );

        return calendar;
    }
    
    /**
     * Test setObject( int, BigInteger ) in JDBC 4.1. See
     * DERBY-5488.
     */
    public  void    testBigInteger() throws  Exception
    {
        Connection conn = getConnection();

        Statement s = conn.createStatement();
        try {
            s.execute( "drop table t2_object_map" );
        } catch (SQLException seq) {}
        s.execute( "create table t2_object_map( smallint_col smallint, int_col int, bigint_col bigint, real_col real, float_col float, double_col double, decimal_col decimal( 31 ), numeric_col numeric( 31 ), char_col char( 10 ), varchar_col varchar( 10 ) )" );

        String[]  allColumns = new String[]
            {
                "smallint_col", "int_col", "bigint_col",
                "real_col", "float_col", "double_col",
                "decimal_col", "numeric_col",
                "char_col", "varchar_col"
            };
        
        HashSet<String> smallIntColumns = new HashSet<String>();
        for ( int i = 0; i < allColumns.length; i++ )
        {
            String  colName = allColumns[ i ];
            if ( colName.endsWith( "int_col" ) ) { smallIntColumns.add( colName ); }
        }

        HashSet<String> smallCharColumns = new HashSet<String>();
        for ( int i = 0; i < allColumns.length; i++ )
        {
            String  colName = allColumns[ i ];
            if ( colName.endsWith( "char_col" ) ) { smallCharColumns.add( colName ); }
        }
        
        vetBigInteger
            (
             conn,
             "1",
             allColumns,
             new HashSet(),
             new HashSet()
             );
        vetBigInteger
            (
             conn,
             "9223372036854775808", // Long.MAX_VALUE + 1
             allColumns,
             smallIntColumns,
             smallCharColumns
             );
        vetBigInteger
            (
             conn,
             "-9223372036854775809", // Long.MIN_VALUE - 1
             allColumns,
             smallIntColumns,
             smallCharColumns
             );
    }
    private void    vetBigInteger
        (
         Connection conn,
         String seed,
         String[] allColumns,
         HashSet undersizedIntColumns,
         HashSet undersizedStringColumns
         )
        throws Exception
    {
        for ( int i = 0; i < allColumns.length; i++ )
        {
            String  columnName = allColumns[ i ];
            String  errorState = null;
            if ( undersizedIntColumns.contains( columnName ) ) { errorState = WONT_FIT; }
            else if ( undersizedStringColumns.contains( columnName ) ) { errorState = TRUNCATED; }

            vetBigInteger( conn, seed, columnName, errorState );
        }
    }
    private void    vetBigInteger
        (
         Connection conn,
         String seed,
         String columnName,
         String errorState
         )
        throws Exception
    {
        PreparedStatement   ps = conn.prepareStatement( "delete from t2_object_map" );
        ps.executeUpdate();
        ps.close();

        String  insertText = "insert into t2_object_map( " + columnName + " ) values ( ? )";
        ps = conn.prepareStatement( insertText );

        try {
            ps.setObject( 1, new BigInteger( seed ) );
            ps.executeUpdate();

            if ( errorState != null ) { fail( "Expected '" + insertText + "' to fail for BigInteger( " + seed + " )." ); }
        }
        catch (SQLException se )
        {
            assertEquals
                ( "Expecting failure for seed = " + seed + " and insertText = '" + insertText + "'" , errorState, se.getSQLState() );
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.apache.derbyTesting.junit.BaseJDBCTestCase#tearDown()
     */
    protected void tearDown() throws Exception {
        rollback();
        dropTable("PM.LOB_GET");
        commit();
        super.tearDown();
    }

    private static void getXXX(PreparedStatement ps, int type, boolean isNull)
            throws SQLException, java.io.IOException {

        // Expect the different getters to return some variant of the integer
        // 32. The exception is BOOLEAN columns, which don't have high enough
        // precision to do that. So expect 1 for BOOLEAN columns.
        final int expectedInt =
                (ps.getMetaData().getColumnType(1) == Types.BOOLEAN) ?
                    1 : 32;

        {
         
            // getByte();
            ResultSet rs = ps.executeQuery();
            rs.next();
            boolean worked;
            SQLException sqleResult = null;
            try {
                byte b = rs.getByte(1);
                boolean wn = rs.wasNull();
                if (isNull) {
                    assertTrue(wn);
                } else {
                    assertFalse(wn);
                    assertEquals(expectedInt, b);
                }
                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            rs.close();
            judge_getXXX(worked, sqleResult, 0, type);
        }

        {
            // getShort()
            ResultSet rs = ps.executeQuery();
            rs.next();
            boolean worked;
            SQLException sqleResult = null;
            try {
                short s = rs.getShort(1);
                boolean wn = rs.wasNull();
                if (isNull) {
                    assertTrue(wn);
                } else {
                    assertFalse(wn);
                    assertEquals(expectedInt, s);
                }
                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            rs.close();
            judge_getXXX(worked, sqleResult, 1, type);
        }

        {
            // getInt()
            ResultSet rs = ps.executeQuery();
            rs.next();
            boolean worked;
            SQLException sqleResult = null;
            try {
                int i = rs.getInt(1);
                boolean wn = rs.wasNull();
                if (isNull) {
                    assertTrue(wn);
                } else {
                    assertFalse(isNull);
                    assertEquals(expectedInt, i);
                }
                worked = true;
            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            rs.close();
            judge_getXXX(worked, sqleResult, 2, type);
        }

        {
            // getLong();
            ResultSet rs = ps.executeQuery();
            rs.next();
            boolean worked;
            SQLException sqleResult = null;
            try {
                long l = rs.getLong(1);
                boolean wn = rs.wasNull();
                if (isNull) {
                    assertTrue(wn);
                } else {
                    assertEquals(expectedInt, l);
                    assertFalse(wn);
                }
                worked = true;
            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            rs.close();
            judge_getXXX(worked, sqleResult, 3, type);
        }

        {
            // getFloat()

            ResultSet rs = ps.executeQuery();
            rs.next();
            boolean worked;
            SQLException sqleResult = null;
            try {
                float f = rs.getFloat(1);
                boolean wn = rs.wasNull();

                if (isNull) {
                    assertTrue(wn);
                } else {
                    assertFalse(wn);
                    assertEquals((float) expectedInt, f, .000001);
                }
                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            rs.close();
            judge_getXXX(worked, sqleResult, 4, type);
        }

        {
            // getDouble();
            ResultSet rs = ps.executeQuery();
            rs.next();
            SQLException sqleResult = null;
            boolean worked;
            try {
                double d = rs.getDouble(1);
                boolean wn = rs.wasNull();
                if (isNull) {
                    assertTrue(wn);
                } else {
                    assertFalse(wn);
                    assertEquals((double) expectedInt, d, .00001);
                }
                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            rs.close();
            judge_getXXX(worked, sqleResult, 5, type);
        }

        if (HAVE_BIG_DECIMAL) {
            // getBigDecimal()
            ResultSet rs = ps.executeQuery();
            rs.next();
            boolean worked;
            SQLException sqleResult = null;
            try {
                BigDecimal bd = rs.getBigDecimal(1);
                boolean wn = rs.wasNull();
                if (isNull) {
                    assertTrue(wn);
                    assertNull(bd);
                } else {
                    assertFalse(wn);
                    assertEquals("BigDecimal comparison failed", 0,
                            BigDecimal.valueOf(
                                    (long)expectedInt).compareTo(bd));
                }
                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            rs.close();
            judge_getXXX(worked, sqleResult, 6, type);
        }

        {
            // getBoolean()
            ResultSet rs = ps.executeQuery();
            rs.next();
            boolean worked;
            SQLException sqleResult = null;
            try {
                boolean b = rs.getBoolean(1);
                boolean wn = rs.wasNull();
                if (isNull) {
                    assertTrue(wn);
                } else {
                    assertFalse(wn);
                    assertTrue(b);
                }
                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            rs.close();
            judge_getXXX(worked, sqleResult, 7, type);
        }

        {
            // getString()
            ResultSet rs = ps.executeQuery();
            rs.next();
            boolean worked;
            SQLException sqleResult = null;
            try {
                String s = rs.getString(1);
                boolean wn = rs.wasNull();
                if (isNull) {
                    assertNull(s);
                    assertTrue(wn);
                } else {                    
                    s = s.trim();
                    int jdbcType = jdbcTypes[type];
                    switch(jdbcType) {
                    case java.sql.Types.SMALLINT:
                    case java.sql.Types.INTEGER:
                    case java.sql.Types.BIGINT:
                    case java.sql.Types.CHAR:
                    case java.sql.Types.VARCHAR:
                    case java.sql.Types.LONGVARCHAR:
                        assertEquals(Integer.toString(expectedInt),s);
                        break;
                    case java.sql.Types.REAL:
                    case java.sql.Types.FLOAT:
                    case java.sql.Types.DOUBLE:
                        assertEquals(expectedInt + ".0",s);
                        break;
                    case java.sql.Types.DECIMAL:
                    case java.sql.Types.NUMERIC:
                        assertEquals(expectedInt + ".00000",s);
                        break;
                    case java.sql.Types.VARBINARY:
                    case java.sql.Types.BINARY:
                        assertEquals("0403fdc373",s);
                        break;
                    case java.sql.Types.DATE:
                        assertEquals("2004-02-14",s);
                        break;
                    case java.sql.Types.TIME:
                        assertEquals("17:14:24",s);
                        break;
                    case java.sql.Types.TIMESTAMP:
                        assertEquals("2004-02-14 17:14:24.097625551",s);
                        break;
                    case java.sql.Types.CLOB:
                        assertEquals("67",s);
                        break;
                    case java.sql.Types.BLOB:
                        assertEquals("8243cafe0032",s);
                        break;
                    }
                    
                    assertFalse(wn);
                }
                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            rs.close();
            judge_getXXX(worked, sqleResult, 8, type);
        }

        {
            // getBytes()
            ResultSet rs = ps.executeQuery();
            rs.next();
            boolean worked;
            SQLException sqleResult = null;
            try {
                byte[] data = rs.getBytes(1);
                boolean wn = rs.wasNull();
                if (isNull) {
                    assertNull(data);
                    assertTrue(wn);
                } else {
                    int jdbcType = jdbcTypes[type];
                    switch (jdbcType) {
                    case java.sql.Types.BINARY:
                    case java.sql.Types.VARBINARY:
                    case java.sql.Types.LONGVARBINARY:
                        assertEquals("0x4,0x3", showFirstTwo(data));
                        break;
                    case java.sql.Types.BLOB:
                        assertEquals("0x82,0x43", showFirstTwo(data));
                    }
                    assertNotNull(data);
                    assertFalse(wn);
                }
                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            rs.close();
            judge_getXXX(worked, sqleResult, 9, type);
        }

        {
            // getDate()

            boolean worked;
            SQLException sqleResult = null;
            ResultSet rs = null;
            try {
                rs = ps.executeQuery();
                rs.next();
                Date d = rs.getDate(1);
                boolean wn = rs.wasNull();
                if (isNull) {
                    assertNull(d);
                    assertTrue(wn);
                } else {
                    assertEquals("2004-02-14", d.toString());
                    assertNotNull(d);
                    assertFalse(wn);
                }
                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                // 22007 invalid date time conversion
                worked = "22007".equals(sqle.getSQLState());
            } catch (Throwable t) {
                // System.out.print(t.toString());
                worked = false;
            }
            if (rs != null)
                rs.close();
            judge_getXXX(worked, sqleResult, 10, type);
        }

        {
            boolean worked;
            SQLException sqleResult = null;
            ResultSet rs = null;
            try {
                // getTime()
                rs = ps.executeQuery();
                rs.next();
                Time t = rs.getTime(1);
                boolean wn = rs.wasNull();
                if (isNull) {
                    assertNull(t);
                    assertTrue(wn);
                } else {
                    assertFalse(wn);
                    assertEquals("17:14:24", t.toString());
                }
                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                // 22007 invalid date time conversion
                worked = "22007".equals(sqle.getSQLState());
            } catch (Throwable t) {
                // System.out.println(t);
                worked = false;
            }
            if (rs != null)
                rs.close();
            judge_getXXX(worked, sqleResult, 11, type);
        }

        {
            boolean worked;
            SQLException sqleResult = null;
            ResultSet rs = null;
            try {
                // getTimestamp();
                rs = ps.executeQuery();
                rs.next();
                Timestamp ts = rs.getTimestamp(1);
                boolean wn = rs.wasNull();
                if (isNull) {
                    assertNull(ts);
                    assertTrue(wn);
                } else {
                    if (type == java.sql.Types.DATE
                            || type == java.sql.Types.TIMESTAMP)
                        assertEquals("2004-02-14 00:00:00.0", ts.toString());
                    assertFalse(rs.wasNull());
                }
                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                // 22007 invalid date time conversion
                worked = "22007".equals(sqle.getSQLState());
            } catch (Throwable t) {
                // System.out.println(t);
                worked = false;
            }
            if (rs != null)
                rs.close();
            judge_getXXX(worked, sqleResult, 12, type);
        }

        {
            // getAsciiStream()

            ResultSet rs = ps.executeQuery();
            rs.next();
            boolean worked;
            SQLException sqleResult = null;
            try {
                InputStream is = rs.getAsciiStream(1);
                boolean wn = rs.wasNull();
                if (isNull) {
                    assertTrue(wn);
                    assertNull(is);
                } else {
                    assertFalse(wn);
                    if (B6[13][type])
                        assertNotNull(showFirstTwo(is));
                }

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }

            // getAsciiStream on a NULL value for an invalid conversion
            // is handled differently in JCC to Cloudscape. On a non-NULL
            // value an exception is correctly raised by both JCC and CS.
            // here we check this specific case to reduce canon differences
            // between CNS and CS.

            boolean judge = B6[13][type]
                    || specificCheck(rs, worked, sqleResult, isNull);
            rs.close();
            if (judge)
                judge_getXXX(worked, sqleResult, 13, type);
        }

        {
            // getBinaryStream()
            ResultSet rs = ps.executeQuery();
            rs.next();
            boolean worked;
            SQLException sqleResult = null;
            try {
                InputStream is = rs.getBinaryStream(1);
                if (isNull) {
                    assertTrue(rs.wasNull());
                    assertNull(is);

                } else if (B6[14][type]) {
                    assertNotNull(showFirstTwo(is));
                }
                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            boolean judge = B6[14][type]
                    || specificCheck(rs, worked, sqleResult, isNull);
            rs.close();
            if (judge)
                judge_getXXX(worked, sqleResult, 14, type);
        }

        {
            // getCharacterStream()
            ResultSet rs = ps.executeQuery();
            rs.next();
            boolean worked;
            SQLException sqleResult = null;
            try {

                Reader r = rs.getCharacterStream(1);
                boolean wn = rs.wasNull();
                if (isNull) {
                    assertNull(r);
                    assertTrue(wn);
                } else if (B6[15][type]) {
                    assertFalse(wn);
                    assertNotNull(showFirstTwo(r));
                }
                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            boolean judge = B6[15][type]
                    || specificCheck(rs, worked, sqleResult, isNull);
            rs.close();
            if (judge)
                judge_getXXX(worked, sqleResult, 15, type);
        }

        {
            // getClob();
            ResultSet rs = ps.executeQuery();
            rs.next();
            boolean worked;
            SQLException sqleResult = null;
            try {
                Clob clob = rs.getClob(1);
                boolean wn = rs.wasNull();
                if (isNull) {
                    assertNull(clob);
                    assertTrue(wn);
                } else if (B6[16][type]) {
                    assertFalse(wn);
                    assertNotNull(clob.getSubString(1, 10));
                }
                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            boolean judge = B6[16][type]
                    || specificCheck(rs, worked, sqleResult, isNull);
            rs.close();
            if (judge)
                judge_getXXX(worked, sqleResult, 16, type);
        }

        {
            // getBlob()

            ResultSet rs = ps.executeQuery();
            rs.next();
            boolean worked;
            SQLException sqleResult = null;
            try {
                Blob blob = rs.getBlob(1);
                boolean wn = rs.wasNull();
                if (isNull) {
                    assertTrue(wn);
                    assertNull(blob);
                } else if (B6[17][type]) {
                    assertNotNull(showFirstTwo(blob.getBinaryStream()));
                }
                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            boolean judge = B6[17][type]
                    || specificCheck(rs, worked, sqleResult, isNull);
            rs.close();
            if (judge)
                judge_getXXX(worked, sqleResult, 17, type);
        }

        {
            // getUnicodeStream()
            ResultSet rs = ps.executeQuery();
            rs.next();
            boolean worked;
            SQLException sqleResult = null;
            try {
                // We want to test that getUnicodeStream() works, even though
                // it's deprecated. Suppress the compiler warning.
                @SuppressWarnings("deprecation")
                InputStream is = rs.getUnicodeStream(1);
                boolean wn = rs.wasNull();
                if (isNull) {
                    assertTrue(wn);
                    assertNull(is);

                } else {
                    assertFalse(wn);
                    assertNotNull(is);
                }
                worked = true;
            } catch (NoSuchMethodError e) {
                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            rs.close();
            if (JDBC.vmSupportsJDBC3())
                judge_getXXX(worked, sqleResult, 18, type);
        }

        // Check to see getObject returns the correct type
        {
            // getObject();
            ResultSet rs = ps.executeQuery();
            rs.next();
            try {

                boolean worked;
                if (!SQLTypes[type].equals("DECIMAL(10,5)") || HAVE_BIG_DECIMAL) {
                    Object o = rs.getObject(1);
                    boolean wn = rs.wasNull();
                    Class cgo = B3_GET_OBJECT[type];

                    String cname;
                    if (cgo.equals(byte[].class))
                        cname = "byte[]";
                    else
                        cname = cgo.getName();
                    if (isNull) {
                        assertTrue(wn);
                        assertNull(o);
                        worked = true;
                    } else if (cgo.isInstance(o)) {
                        worked = true;
                    } else {
                        worked = false;
                        fail("FAIL NOT :" + cgo.getName() + " is "
                                + o.getClass().getName());
                    }
                } else {
                    // "ResultSet.getObject not called for DECIMAL type for
                    // JSR169";
                    worked = true;
                }
                assertTrue(worked);

            } catch (SQLException sqle) {
                throw sqle; // Just pass this on to fail the test.
            }
            rs.close();
        }

    }

    private static boolean specificCheck(ResultSet rs, boolean worked,
            SQLException sqleResult, boolean isNull) throws SQLException {
        boolean judge = true;
        if (worked && isNull && rs.wasNull()) {
            // JCC returns NULL
            if (usingDerbyNetClient())
                judge = false;
        } else if (!worked && isNull) {
            if (usingDerbyNetClient()
                    && "22005".equals(sqleResult.getSQLState()))
                judge = false;
        }

        return judge;
    }

    private static void judge_getXXX(boolean worked, SQLException sqleResult,
            int whichCall, int type) {
        boolean validSQLState = false;
        // verify valid conversion worked
        if (B6[whichCall][type] && !worked)
            fail(" JDBC FAIL " + SQLTypes[type] + " " + sqleResult);
        else if (!worked) {
            // make sure not implemented or conversion error was thrown if it
            // didn't work
            String sqlState = sqleResult.getSQLState();
            if ("0A000".equals(sqlState))
                validSQLState = true;
            if ("0A000".equals(sqlState))
                validSQLState = true;
            if ("22005".equals(sqlState))
                // embedded invalid conversion error
                validSQLState = true;
            else if (sqlState == null) {
                // client invalid conversion error
                if (sqleResult.getMessage().indexOf(
                        "Wrong result column type for requested conversion") != -1)
                    validSQLState = true;
            }
            assertTrue("FAIL: Expected conversion error but got " + sqleResult,
                    validSQLState);

        }

    }

    private static void judge_setXXX(boolean worked, SQLException sqleResult,
            int whichCall, int type) {
        String msg;
        boolean shouldWork = B2_MOD[whichCall][type];

        if (worked && shouldWork)
            msg = " JDBC MATCH(OK)";
        else if (worked)
            msg = " CLOUD EXT (OK)";
        else if (sqleResult != null && "0A000".equals(sqleResult.getSQLState()))
            msg = " Not Implemented (OK)";
        else if (shouldWork) {
            if (sqleResult != null)
                showException(sqleResult);
            msg = " JDBC FAIL " + SQLTypes[type];
        } else {
            msg = checkForInvalidConversion(sqleResult);
            if (msg == null)
                return;
        }
        if (msg.startsWith("JDBC FAIL"))
            fail(" JDBC FAIL " + SQLTypes[type]);
    }

    private static void judge_setObject(boolean worked,
            SQLException sqleResult, int b5o, int type) {
        String msg;
        boolean shouldWork = B5[b5o][type];

        if (worked && shouldWork)
            msg = " JDBC MATCH(OK)";
        else if (worked)
            msg = " CLOUD EXT (OK)";
        else if ("0A000".equals(sqleResult.getSQLState()))
            msg = " Not Implemented (OK)";
        else if (shouldWork) {
            if (sqleResult != null)
                showException(sqleResult);
            msg = " JDBC FAIL " + SQLTypes[type];
        } else {
            msg = checkForInvalidConversion(sqleResult);
            if (msg == null)
                return;
        }
        if (msg.startsWith("JDBC FAIL"))
            fail(" JDBC FAIL " + SQLTypes[type]);
    }

    /**
     * Look for an "Invalid Conversion" exception and format it for display.
     * 
     * Look for an "Invalid Conversion" exception. If one is found, print "IC".
     * If one is not found, dump the actual exception to the output instead.
     * 
     * Note that the actual invalid conversion exception may be wrapped inside a
     * BatchUpdateException, so we may need to hunt through the exception chain
     * to find it.
     */
    private static String checkForInvalidConversion(SQLException sqle) {
        if (sqle == null)
            return null;

        boolean unknownException = true;
        SQLException e = sqle;
        while (e != null && unknownException == true) {
            // XCL12 is temp
            if ("22005".equals(e.getSQLState())
                    || "XCL12".equals(e.getSQLState())
                    || e.getMessage().indexOf("Illegal Conv") != -1) {
                unknownException = false;
                if ("0A000".equals(e.getSQLState())
                        && e.getMessage().indexOf("setUnicodeStream") != -1)
                    unknownException = false;

                // System.out.print("IC");
                break;
            }
            e = e.getNextException();
        }
        if (unknownException)
            showException(sqle);

        return " JDBC MATCH (INVALID)";
    }

    private static void setXXX(Statement s, PreparedStatement psi,
            PreparedStatement psq, int type) throws SQLException,
            java.io.IOException {

        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setByte()
                psi.setByte(1, (byte) 98);
                psi.executeUpdate();

                getValidValue(psq, jdbcTypes[type], "setByte");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 0, type);
        }
        // and as a batch
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                psi.setByte(1, (byte) 98);
                psi.addBatch();
                psi.executeBatch();

                getValidValue(psq, jdbcTypes[type], "setByte");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 0, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setShort()
                psi.setShort(1, (short) 98);
                psi.executeUpdate();

                getValidValue(psq, jdbcTypes[type], "setShort");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 1, type);
        }
        // and as a batch
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setShort() as batch
                psi.setShort(1, (short) 98);
                psi.addBatch();
                psi.executeBatch();

                getValidValue(psq, jdbcTypes[type], "setShort");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 1, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setInt()
                psi.setInt(1, 98);
                psi.executeUpdate();

                getValidValue(psq, jdbcTypes[type], "setInt");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 2, type);
        }
        // and as a batch
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setInt() as batch
                psi.setInt(1, 98);
                psi.addBatch();
                psi.executeBatch();

                getValidValue(psq, jdbcTypes[type], "setInt");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 2, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setLong()
                psi.setLong(1, 98L);
                psi.executeUpdate();

                getValidValue(psq, jdbcTypes[type], "setLong");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 3, type);
        }
        // as a batch
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setLong() as batch
                psi.setLong(1, 98L);
                psi.addBatch();
                psi.executeBatch();

                getValidValue(psq, jdbcTypes[type], "setLong");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 3, type);
        }

        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setFloat()
                psi.setFloat(1, 98.4f);
                psi.executeUpdate();

                getValidValue(psq, jdbcTypes[type], "setFloat");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 4, type);
        }

        // and as a batch
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setFloat() as batch
                psi.setFloat(1, 98.4f);
                psi.addBatch();
                psi.executeBatch();

                getValidValue(psq, jdbcTypes[type], "setFloat");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 4, type);
        }

        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setDouble()
                psi.setDouble(1, 98.5);
                psi.executeUpdate();

                getValidValue(psq, jdbcTypes[type], "setDouble");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 5, type);
        }

        // as a batch
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setDouble() as batch
                psi.setDouble(1, 98.5);
                psi.addBatch();
                psi.executeBatch();

                getValidValue(psq, jdbcTypes[type], "setDouble");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 5, type);
        }

        if (HAVE_BIG_DECIMAL) {
            {
                s.execute("DELETE FROM PM.TYPE_AS");

                SQLException sqleResult = null;
                boolean worked;
                try {
                    // setBigDecimal()
                    psi.setBigDecimal(1, new BigDecimal(98.0));
                    psi.executeUpdate();

                    getValidValue(psq, jdbcTypes[type], "setBigDecimal");

                    worked = true;

                } catch (SQLException sqle) {
                    sqleResult = sqle;
                    worked = false;
                }
                judge_setXXX(worked, sqleResult, 6, type);
            }
            // as a batch
            {
                s.execute("DELETE FROM PM.TYPE_AS");

                SQLException sqleResult = null;
                boolean worked;
                try {
                    // setBigDecimal() as batch
                    psi.setBigDecimal(1, new BigDecimal(98.0));
                    psi.addBatch();
                    psi.executeBatch();

                    getValidValue(psq, jdbcTypes[type], "setBigDecimal");

                    worked = true;

                } catch (SQLException sqle) {
                    sqleResult = sqle;
                    worked = false;
                }
                judge_setXXX(worked, sqleResult, 6, type);
            }
            // null BigDecimal
            {
                s.execute("DELETE FROM PM.TYPE_AS");

                SQLException sqleResult = null;
                boolean worked;
                try {
                    // setBigDecimal(null)
                    psi.setBigDecimal(1, null);
                    psi.executeUpdate();

                    getValidValue(psq, jdbcTypes[type], "setBigDecimal");

                    worked = true;

                } catch (SQLException sqle) {
                    sqleResult = sqle;
                    worked = false;
                }
                judge_setXXX(worked, sqleResult, 6, type);
            }

            // null BigDecimal
            {
                s.execute("DELETE FROM PM.TYPE_AS");

                SQLException sqleResult = null;
                boolean worked;
                try {
                    // setBigDecimal(null) as batch
                    psi.setBigDecimal(1, null);
                    psi.addBatch();
                    psi.executeBatch();

                    getValidValue(psq, jdbcTypes[type], "setBigDecimal");

                    worked = true;

                } catch (SQLException sqle) {
                    sqleResult = sqle;
                    worked = false;
                }
                judge_setXXX(worked, sqleResult, 6, type);
            }
        }

        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setBoolean()
                psi.setBoolean(1, true);
                psi.executeUpdate();

                getValidValue(psq, jdbcTypes[type], "setBoolean");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 7, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setBoolean() as batch
                psi.setBoolean(1, true);
                psi.addBatch();
                psi.executeBatch();

                getValidValue(psq, jdbcTypes[type], "setBoolean");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 7, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                
                psi.setString(1,validString[type]);
                psi.executeUpdate();

                getValidValue(psq, jdbcTypes[type], "setString");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            } catch (Throwable t) {
                // JCC has some bugs
                // System.out.println(t.getMessage());
                worked = false;
                sqleResult = null;

            }
            judge_setXXX(worked, sqleResult, 8, type);
        }
        // as batch
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setString() as batch
               
                psi.setString(1,validString[type]);
                psi.addBatch();
                psi.executeBatch();

                getValidValue(psq, jdbcTypes[type], "setString");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            } catch (Throwable t) {
                // JCC has some bugs
                // System.out.println(t.getMessage());
                worked = false;
                sqleResult = null;

            }
            judge_setXXX(worked, sqleResult, 8, type);
        }

        // null String
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setString(null)
                psi.setString(1, null);
                psi.executeUpdate();

                getValidValue(psq, jdbcTypes[type], "setString");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            } catch (Throwable t) {
                // JCC has some bugs
                // System.out.println(t.getMessage());
                worked = false;
                sqleResult = null;

            }
            judge_setXXX(worked, sqleResult, 8, type);
        }
        // null String as batch
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setString(null) as batch
                psi.setString(1, null);
                psi.addBatch();
                psi.executeBatch();

                getValidValue(psq, jdbcTypes[type], "setString");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            } catch (Throwable t) {
                // JCC has some bugs
                // System.out.println(t.getMessage());
                worked = false;
                sqleResult = null;

            }
            judge_setXXX(worked, sqleResult, 8, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            // Set Invalid String for nonString types (DERBY-149)
            testSetStringInvalidValue(type, psi);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setBytes()
                byte[] data = { (byte) 0x04, (byte) 0x03, (byte) 0xfd,
                        (byte) 0xc3, (byte) 0x73 };
                psi.setBytes(1, data);
                psi.executeUpdate();

                getValidValue(psq, jdbcTypes[type], "setBytes");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 9, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setBytes() as batch
                byte[] data = { (byte) 0x04, (byte) 0x03, (byte) 0xfd,
                        (byte) 0xc3, (byte) 0x73 };
                psi.setBytes(1, data);
                psi.addBatch();
                psi.executeBatch();

                getValidValue(psq, jdbcTypes[type], "setBytes");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 9, type);
        }
        // null byte[]
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setBytes(null)
                psi.setBytes(1, null);
                psi.executeUpdate();

                getValidValue(psq, jdbcTypes[type], "setBytes");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 9, type);
        }

        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setBytes(null) as batch
                psi.setBytes(1, null);
                psi.addBatch();
                psi.executeBatch();

                getValidValue(psq, jdbcTypes[type], "setBytes");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 9, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setDate()
                psi.setDate(1, java.sql.Date.valueOf("2004-02-14"));
                psi.executeUpdate();

                getValidValue(psq, jdbcTypes[type], "setDate");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 10, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setDate() as batch
                psi.setDate(1, java.sql.Date.valueOf("2004-02-14"));
                psi.addBatch();
                psi.executeBatch();

                getValidValue(psq, jdbcTypes[type], "setDate");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 10, type);
        }
        // null Date
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setDate(null)
                psi.setDate(1, null);
                psi.executeUpdate();

                getValidValue(psq, jdbcTypes[type], "setDate");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 10, type);
        }

        // null Date
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setDate(null) as batch
                psi.setDate(1, null);
                psi.addBatch();
                psi.executeBatch();

                getValidValue(psq, jdbcTypes[type], "setDate");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 10, type);
        }

        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setTime()
                psi.setTime(1, java.sql.Time.valueOf("00:00:00"));
                psi.executeUpdate();

                getValidValue(psq, jdbcTypes[type], "setTime");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 11, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setTime() as batch
                psi.setTime(1, java.sql.Time.valueOf("00:00:00"));
                psi.addBatch();
                psi.executeBatch();

                getValidValue(psq, jdbcTypes[type], "setTime");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 11, type);
        }

        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setTime(null)
                psi.setTime(1, null);
                psi.executeUpdate();

                getValidValue(psq, jdbcTypes[type], "setTime");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 11, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setTime(null) as batch
                psi.setTime(1, null);
                psi.addBatch();
                psi.executeBatch();

                getValidValue(psq, jdbcTypes[type], "setTime");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 11, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setTimestamp()
                psi.setTimestamp(1, java.sql.Timestamp
                        .valueOf("2004-02-14 00:00:00.0"));
                psi.executeUpdate();

                getValidValue(psq, jdbcTypes[type], "setTimestamp");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 12, type);
        }
        // as batch
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setTimestamp() as batch
                psi.setTimestamp(1, java.sql.Timestamp
                        .valueOf("2004-02-14 00:00:00.0"));
                psi.addBatch();
                psi.executeBatch();

                getValidValue(psq, jdbcTypes[type], "setTimestamp");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 12, type);
        }

        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setTimestamp(null)
                psi.setTimestamp(1, null);
                psi.executeUpdate();

                getValidValue(psq, jdbcTypes[type], "setTimestamp");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 12, type);
        }
        // as batch
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setTimestamp(null) as batch
                psi.setTimestamp(1, null);
                psi.addBatch();
                psi.executeBatch();

                getValidValue(psq, jdbcTypes[type], "setTimestamp");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 12, type);
        }

        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setAsciiStream()
                byte[] data = new byte[6];
                data[0] = (byte) 0x65;
                data[1] = (byte) 0x67;
                data[2] = (byte) 0x30;
                data[3] = (byte) 0x31;
                data[4] = (byte) 0x32;
                data[5] = (byte) 0x64;

                psi
                        .setAsciiStream(1, new java.io.ByteArrayInputStream(
                                data), 6);
                psi.executeUpdate();
                getValidValue(psq, jdbcTypes[type], "setAsciiStream");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 13, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setAsciiStream() as batch
                byte[] data = new byte[6];
                data[0] = (byte) 0x65;
                data[1] = (byte) 0x67;
                data[2] = (byte) 0x30;
                data[3] = (byte) 0x31;
                data[4] = (byte) 0x32;
                data[5] = (byte) 0x64;

                psi
                        .setAsciiStream(1, new java.io.ByteArrayInputStream(
                                data), 6);
                psi.addBatch();
                psi.executeBatch();
                getValidValue(psq, jdbcTypes[type], "setAsciiStream");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 13, type);
        }

        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setAsciiStream(null)
                psi.setAsciiStream(1, null, 0);
                psi.executeUpdate();
                getValidValue(psq, jdbcTypes[type], "setAsciiStream");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 13, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setAsciiStream(null) as batch
                psi.setAsciiStream(1, null, 0);
                psi.addBatch();
                psi.executeBatch();
                getValidValue(psq, jdbcTypes[type], "setAsciiStream");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 13, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setBinaryStream()
                byte[] data = new byte[6];
                data[0] = (byte) 0x4;
                data[1] = (byte) 0x3;
                data[2] = (byte) 0xca;
                data[3] = (byte) 0xfe;
                data[4] = (byte) 0x00;
                data[5] = (byte) 0x32;

                psi.setBinaryStream(1, new java.io.ByteArrayInputStream(data),
                        6);
                psi.executeUpdate();
                getValidValue(psq, jdbcTypes[type], "setBinaryStream");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 14, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setBinaryStream() as batch
                byte[] data = new byte[6];
                data[0] = (byte) 0x4;
                data[1] = (byte) 0x3;
                data[2] = (byte) 0xca;
                data[3] = (byte) 0xfe;
                data[4] = (byte) 0x00;
                data[5] = (byte) 0x32;

                psi.setBinaryStream(1, new java.io.ByteArrayInputStream(data),
                        6);
                psi.addBatch();
                psi.executeBatch();
                getValidValue(psq, jdbcTypes[type], "getBinaryStream");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 14, type);
        }

        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setBinaryStream(null)
                psi.setBinaryStream(1, null, 0);
                psi.executeUpdate();
                getValidValue(psq, jdbcTypes[type], "setBinaryStream");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 14, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setBinaryStream(null) as batch
                psi.setBinaryStream(1, null, 0);
                psi.addBatch();
                psi.executeBatch();
                getValidValue(psq, jdbcTypes[type], "setBinaryStream");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 14, type);
        }

        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setCharacterStream()
                psi.setCharacterStream(1, new java.io.StringReader("89"), 2);
                psi.executeUpdate();
                getValidValue(psq, jdbcTypes[type], "setCharacterStream");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 15, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setCharacterStream() as batch
                psi.setCharacterStream(1, new java.io.StringReader("89"), 2);
                psi.addBatch();
                psi.executeBatch();
                getValidValue(psq, jdbcTypes[type], "setCharacterStream");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 15, type);
        }

        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setCharacterStream(null)
                psi.setCharacterStream(1, null, 0);
                psi.executeUpdate();
                getValidValue(psq, jdbcTypes[type], "setCharacterStream");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 15, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setCharacterStream(null) as batch
                psi.setCharacterStream(1, null, 0);
                psi.addBatch();
                psi.executeBatch();
                getValidValue(psq, jdbcTypes[type], "setCharacterStream");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 15, type);
        }

        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setClob()

                ResultSet rsc = s
                        .executeQuery("SELECT C FROM PM.LOB_GET WHERE ID = 1");
                rsc.next();
                Clob tester = rsc.getClob(1);
                rsc.close();

                psi.setClob(1, tester);
                psi.executeUpdate();
                getValidValue(psq, jdbcTypes[type], "setClob");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 16, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setClob() as batch

                ResultSet rsc = s
                        .executeQuery("SELECT C FROM PM.LOB_GET WHERE ID = 1");
                rsc.next();
                Clob tester = rsc.getClob(1);
                rsc.close();

                psi.setClob(1, tester);
                psi.addBatch();
                psi.executeBatch();
                getValidValue(psq, jdbcTypes[type], "setClob");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 16, type);
        }

        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setClob(null)

                psi.setClob(1, (Clob)null);
                psi.executeUpdate();
                getValidValue(psq, jdbcTypes[type], "setClob");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 16, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setClob(null) as batch

                psi.setClob(1, (Clob)null);
                psi.addBatch();
                psi.executeBatch();
                getValidValue(psq, jdbcTypes[type], "setClob");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 16, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");
            SQLException sqleResult = null;
            boolean worked;
            try {
                // setBlob()

                ResultSet rsc = s
                        .executeQuery("SELECT B FROM PM.LOB_GET WHERE ID = 1");
                rsc.next();
                Blob tester = rsc.getBlob(1);
                rsc.close();

                psi.setBlob(1, tester);
                psi.executeUpdate();
                getValidValue(psq, jdbcTypes[type], "setBlob");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 17, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");
            SQLException sqleResult = null;
            boolean worked;
            try {
                // setBlob() as batch

                ResultSet rsc = s
                        .executeQuery("SELECT B FROM PM.LOB_GET WHERE ID = 1");
                rsc.next();
                Blob tester = rsc.getBlob(1);
                rsc.close();

                psi.setBlob(1, tester);
                psi.addBatch();
                psi.executeBatch();
                getValidValue(psq, jdbcTypes[type], "setBlob");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 17, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");
            SQLException sqleResult = null;
            boolean worked;
            try {
                // Blob(null)

                psi.setBlob(1, (Blob)null);
                psi.executeUpdate();
                getValidValue(psq, jdbcTypes[type], "setBlob");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 17, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");
            SQLException sqleResult = null;
            boolean worked;
            try {
                // setBlob(null) as batch

                psi.setBlob(1, (Blob)null);
                psi.addBatch();
                psi.executeBatch();
                getValidValue(psq, jdbcTypes[type], "setBlob");

                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            judge_setXXX(worked, sqleResult, 17, type);
        }
        {
            s.execute("DELETE FROM PM.TYPE_AS");

            SQLException sqleResult = null;
            boolean worked;
            try {
                // setUnicodeStream()
                byte[] data = new byte[6];
                data[0] = (byte) 0x4;
                data[1] = (byte) 0x3;
                data[2] = (byte) 0xca;
                data[3] = (byte) 0xfe;
                data[4] = (byte) 0x00;
                data[5] = (byte) 0x32;

                setUnicodeStream(psi, 1, new java.io.ByteArrayInputStream(
                            data), 6);

                if (JDBC.vmSupportsJDBC3()) {
                    psi.executeUpdate();
                    getValidValue(psq, jdbcTypes[type], "setUnicodeStream");
                }
                worked = true;

            } catch (SQLException sqle) {
                sqleResult = sqle;
                worked = false;
            }
            if (JDBC.vmSupportsJDBC3())
                judge_setXXX(worked, sqleResult, 14, type);
        }

        // DERBY-1938: Test setObject with null and no type specification.
        setXXX_setObjectNullNoTypeSpec(s, psi, psq, type);

        setXXX_setObject(s, psi, psq, type, validString[type], "java.lang.String", 0);
        
        if (HAVE_BIG_DECIMAL)
            setXXX_setObject(s, psi, psq, type, BigDecimal.valueOf(98L),
                    "java.math.BigDecimal", 1);
        setXXX_setObject(s, psi, psq, type, Boolean.TRUE, "java.lang.Boolean",
                2);

        // DERBY-1500: setObject() should work for Byte and Short too.
        setXXX_setObject(s, psi, psq, type, (byte) 98,
                "java.lang.Byte", 1);
        setXXX_setObject(s, psi, psq, type, (short) 98,
                "java.lang.Short", 2);

        setXXX_setObject(s, psi, psq, type, 98,
                "java.lang.Integer", 3);
        setXXX_setObject(s, psi, psq, type, 98, "java.lang.Long", 4);
        setXXX_setObject(s, psi, psq, type, 98.0f,
                "java.lang.Float", 5);
        setXXX_setObject(s, psi, psq, type, 98.0d,
                "java.lang.Double", 6);

        {
            byte[] data = { 0x4, 0x3 };
            setXXX_setObject(s, psi, psq, type, data, "byte[]", 7);
        }

        setXXX_setObject(s, psi, psq, type,
                java.sql.Date.valueOf("2004-02-14"), "java.sql.Date", 8);
        setXXX_setObject(s, psi, psq, type, java.sql.Time.valueOf("00:00:00"),
                "java.sql.Time", 9);
        setXXX_setObject(s, psi, psq, type, java.sql.Timestamp
                .valueOf("2004-02-14 00:00:00.0"), "java.sql.Timestamp", 10);
        s.getConnection().commit();

        // Test setObject with Blob
        {
            ResultSet rsc = s
                    .executeQuery("SELECT B FROM PM.LOB_GET WHERE ID = 1");
            rsc.next();
            Blob tester = rsc.getBlob(1);
            rsc.close();
            setXXX_setObject(s, psi, psq, type, tester, "java.sql.Blob", 11);
        }

        // Test setObject with Clob
        {
            ResultSet rsc = s
                    .executeQuery("SELECT C FROM PM.LOB_GET WHERE ID = 1");
            rsc.next();
            Clob tester = rsc.getClob(1);
            rsc.close();
            setXXX_setObject(s, psi, psq, type, tester, "java.sql.Clob", 12);
        }

        // Test setObject with java.util.Date (DERBY-5488)
        setXXX_setObject(s, psi, psq, type, new BigInteger( Long.toString( BIG_INTEGER_SEED ) ), "java.math.BigInteger", 15);
        setXXX_setObject(s, psi, psq, type, new java.util.Date( DATE_SEED ), "java.util.Date", 16);
        setXXX_setObject(s, psi, psq, type, makeCalendar( CALENDAR_SEED ), "java.util.Calendar", 17);
    }

    /**
     * Helper method for calling the deprecated {@code setUnicodeStream()}
     * method without getting deprecation warnings from the compiler.
     */
    @SuppressWarnings("deprecation")
    private static void setUnicodeStream(PreparedStatement ps,
                  int parameterIndex, InputStream stream, int length)
            throws SQLException {
        ps.setUnicodeStream(parameterIndex, stream, length);
    }

    /**
     * Do the {@code setObject()} tests for {@code setXXX()}. Test both for
     * the two-argument {@code setObject(int,Object)} method and the
     * three-argument {@code setObject(int,Object,int)} method.
     */
    private static void setXXX_setObject(Statement s, PreparedStatement psi,
            PreparedStatement psq, int type, Object value, String className,
            int b5o) throws SQLException, java.io.IOException {

        // Test setObject(int, Object)
        setXXX_setObject_doWork(
                s, psi, psq, type, value, className, b5o, false, false);

        // Test setObject(int, Object) with batch execution
        setXXX_setObject_doWork(
                s, psi, psq, type, value, className, b5o, false, true);

        // Test setObject(int, Object, int)
        setXXX_setObject_doWork(
                s, psi, psq, type, value, className, b5o, true, false);

        // Test setObject(int, Object, int) with batch execution
        setXXX_setObject_doWork(
                s, psi, psq, type, value, className, b5o, true, true);

    }

    /**
     * Helper method that does all the work for setXXX_setObject().
     *
     * @param withTypeFlag if true, use the setObject() method that takes a
     * type parameter; otherwise, use the two-argument type-less setObject()
     * method
     * @param batchExecution if true, do batch execution; otherwise, do
     * normal execution
     */
    private static void setXXX_setObject_doWork(
            Statement s, PreparedStatement psi, PreparedStatement psq,
            int type, Object value, String className, int b5o,
            boolean withTypeFlag, boolean batchExecution)
        throws SQLException, IOException
    {
        int jdbcType = jdbcTypes[type];
        String method = "setObject(" + className + ")";

        s.execute("DELETE FROM PM.TYPE_AS");

        SQLException sqleResult = null;
        boolean worked;
        try {
            // Set the parameter value, either with or without explicit type
            if (withTypeFlag) {
                psi.setObject(1, value, jdbcType);
            } else {
                psi.setObject(1, value);
            }

            // Execute the statement, either single execution or batch
            if (batchExecution) {
                psi.addBatch();
                psi.executeBatch();
            } else {
                psi.executeUpdate();
            }

            // Check if we got a valid value back
            getValidValue(psq, jdbcType, method);
            worked = true;
        } catch (SQLException sqle) {
            sqleResult = sqle;
            worked = false;
        }

        // Check if the we got the correct response
        judge_setObject(worked, sqleResult, b5o, type);
    }

    /**
     * Passes Java null to the setObject-call, expecting the driver to set the
     * column value to SQL NULL.
     * <p>
     * This behavior was allowed/introduced by DERBY-1938.
     *
     * @param s statement used for auxiliary tasks
     * @param psi statement used for insert
     * @param psq statement used for query (retrieving inserted value)
     * @param type the type of the column
     */
    private static void setXXX_setObjectNullNoTypeSpec(
            Statement s, PreparedStatement psi, PreparedStatement psq,
            int type) throws SQLException, IOException {
        // setObject(null) - see DERBY-1938
        s.execute("DELETE FROM PM.TYPE_AS");

        // setObject(null)
        psi.setObject(1, null);
        psi.executeUpdate();
        getValidValue(psq, jdbcTypes[type], "setObject");

        s.execute("DELETE FROM PM.TYPE_AS");

        // setObject(null) as batch
        psi.setObject(1, null);
        psi.addBatch();
        psi.executeBatch();
        getValidValue(psq, jdbcTypes[type], "setObject");
    }

    /**
     * Fails the test, doing some processing on the SQL state and exception
     * message.
     * <p>
     * The method accepts a {@code null} SQLState and a {@code null} exception
     * message, although these conditions would normally be considered as bugs.
     *
     * @param sqle the cause of the failure
     */
    private static void showException(SQLException sqle) {
        String state = sqle.getSQLState();
        if (state == null)
            state = "?????";

        String msg = sqle.getMessage();
        if (msg == null)
            msg = "?? no message ??";
        fail(" (" + state + "):" + msg, sqle);
    }

    private static boolean setValidValue(PreparedStatement ps, int param,
            int jdbcType) throws SQLException {

        switch (jdbcType) {
        case Types.BIT:
        case Types.BOOLEAN:
            ps.setBoolean(param, true);
            return true;
        case Types.TINYINT:
            ps.setByte(param, (byte) 32);
            return true;
        case Types.SMALLINT:
            ps.setShort(param, (short) 32);
            return true;
        case Types.INTEGER:
            ps.setInt(param, 32);
            return true;
        case Types.BIGINT:
            ps.setLong(param, 32L);
            return true;
        case Types.REAL:
            ps.setFloat(param, 32.0f);
            return true;
        case Types.FLOAT:
        case Types.DOUBLE:
            ps.setDouble(param, 32.0);
            return true;
        case Types.DECIMAL:
            BigDecimalHandler.setBigDecimalString(ps, param, "32.0");
            return true;
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            ps.setString(param, "32");
            return true;
        case Types.BINARY:
        case Types.VARBINARY: {
            byte[] data = { (byte) 0x04, (byte) 0x03, (byte) 0xfd, (byte) 0xc3,
                    (byte) 0x73 };
            ps.setBytes(param, data);
            return true;
        }
            // Types.LONGVARBINARY:
        case Types.DATE:
            ps.setDate(param, java.sql.Date.valueOf("2004-02-14"));
            return true;
        case Types.TIME:
            ps.setTime(param, java.sql.Time.valueOf("17:14:24"));
            return true;
        case Types.TIMESTAMP:
            ps.setTimestamp(param, java.sql.Timestamp
                    .valueOf("2004-02-14 17:14:24.097625551"));
            return true;
        case Types.CLOB:
            // JDBC 3.0 spec section 16.3.2 explictly states setCharacterStream
            // is OK for setting a CLOB
            ps.setCharacterStream(param, new java.io.StringReader("67"), 2);
            return true;
        case Types.BLOB:
            // JDBC 3.0 spec section 16.3.2 explictly states setBinaryStream is
            // OK for setting a BLOB
        {
            byte[] data = new byte[6];
            data[0] = (byte) 0x82;
            data[1] = (byte) 0x43;
            data[2] = (byte) 0xca;
            data[3] = (byte) 0xfe;
            data[4] = (byte) 0x00;
            data[5] = (byte) 0x32;

            ps
                    .setBinaryStream(param, new java.io.ByteArrayInputStream(
                            data), 6);
            return true;
        }
        default:
            return false;
        }
    }

    private static boolean getValidValue(PreparedStatement ps, int jdbcType,
            String method) throws SQLException, IOException {

        ResultSet rs = ps.executeQuery();
        rs.next();

        switch (jdbcType) {
        case Types.SMALLINT: {
            short val = rs.getShort(1);
            boolean wn = rs.wasNull();

            if (wn)
                assertEquals(0, val);
            else if (isBooleanMethod(method))
                assertEquals(1, val);
            else
                assertEquals(98, val);
            return true;
        }
        case Types.INTEGER: {
            int val = rs.getInt(1);
            boolean wn = rs.wasNull();
            if (wn)
                assertEquals(0, val);
            else if (isBooleanMethod(method))
                assertEquals(1, val);
            else
                assertEquals(98, val);
            return true;
        }
        case Types.BIGINT: {
            long val = rs.getLong(1);
            boolean wn = rs.wasNull();
            if (wn)
                assertEquals(0, val);
            else if (isBooleanMethod(method))
                assertEquals(1, val);
            else
                assertEquals(98, val);
            return true;
        }
        case Types.REAL: {
            float val = rs.getFloat(1);
            boolean wn = rs.wasNull();
            if (wn)
                assertEquals(0.0, val, .001);
            else if (isBooleanMethod(method))
                assertEquals(1.0, val, .001);
            else if (method.equals("setFloat"))
                assertEquals(98.4, val, .001);
            else if (method.equals("setDouble"))
                assertEquals(98.5, val, .001);
            else
                assertEquals(98.0, val, .001);
            return true;
        }
        case Types.FLOAT:
        case Types.DOUBLE: {
            double val = rs.getDouble(1);
            boolean wn = rs.wasNull();
            if (wn)
                assertEquals(0.0, val, .001);
            else if (isBooleanMethod(method))
                assertEquals(1.0, val, .001);
            else if (method.equals("setFloat"))
                assertEquals(98.4, val, .001);
            else if (method.equals("setDouble"))
                assertEquals(98.5, val, .001);
            else
                assertEquals(98.0, val, .001);
            return true;
        }
        case Types.DECIMAL: {
            String val = BigDecimalHandler.getBigDecimalString(rs, 1);
            boolean wn = rs.wasNull();
            if (wn)
                assertNull(val);
            else if (isBooleanMethod(method))
                assertEquals("1.00000", val);
            else if (method.equals("setFloat"))
                assertEquals("98.40000", val);
            else if (method.equals("setDouble"))
                assertEquals("98.50000", val);
            else
                assertEquals("98.00000", val);
            return true;
        }
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR: {
            String s = rs.getString(1);
            boolean wn = rs.wasNull();
            if (wn)
                assertNull(s);
            else {
                // With IBM's DB2 universal driver.
                // Setting a java.sql.Clob value works with
                // a character column but sets the value to
                // be the object's toString. This is probably a bug with JCC.
                if (s.startsWith("com.ibm.db2.jcc.")
                        || s.startsWith("org.apache.derby.client"))
                    s = "<OBJECT.toString()>";

                boolean hasNonAscii = false;
                // check for any characters in the control range
                for (int si = 0; si < s.length(); si++) {
                    char c = s.charAt(si);
                    if (c < (char) 0x20 || c >= (char) 0x7f) {
                        hasNonAscii = true;
                        break;
                    }
                }

                if (hasNonAscii) {
                    StringBuffer sb = new StringBuffer();

                    sb.append("EncodedString: >");
                    for (int si = 0; si < s.length(); si++) {
                        sb.append(' ');
                        sb.append((int) s.charAt(si));
                    }
                    sb.append(" <");
                    s = sb.toString();

                }
                checkValidStringValue(method, s);
            }
            return true;
        }
        case Types.BINARY:
        case Types.VARBINARY: {
            byte[] data = rs.getBytes(1);
            boolean wn = rs.wasNull();
            if (wn)
                assertNull(data);
            else
                assertEquals("0x4,0x3", showFirstTwo(data));
            return true;
        }
        case Types.LONGVARBINARY: {
            InputStream is = rs.getBinaryStream(1);
            boolean wn = rs.wasNull();
            if (wn)
                assertNull(is);
            else
                assertEquals("0x4,0x3", showFirstTwo(is));
            return true;
        }
        case Types.DATE: {
            Date d = rs.getDate(1);
            boolean wn = rs.wasNull();
            if (wn)
                assertNull(d);
            else
            {
                if ( DATE_METHOD_NAME.equals(method) )
                {
                    assertEquals( (new java.sql.Date( DATE_SEED )).toString(), d.toString() );
                }
                else if ( CALENDAR_METHOD_NAME.equals(method) )
                {
                    assertEquals( (new java.sql.Date( CALENDAR_SEED )).toString(), d.toString() );
                }
                else
                {
                    assertEquals(Date.valueOf("2004-02-14"), d);
                }
            }
            return true;
        }
        case Types.TIME: {
            Time t = rs.getTime(1);
            boolean wn = rs.wasNull();
            if (wn)
                assertNull(t);
            else
            {
                if ( DATE_METHOD_NAME.equals(method) )
                {
                    assertEquals( (new java.sql.Time( DATE_SEED )).toString(), t.toString() );
                }
                else if ( CALENDAR_METHOD_NAME.equals(method) )
                {
                    assertEquals( (new java.sql.Time( CALENDAR_SEED )).toString(), t.toString() );
                }
                else
                {
                    assertEquals(Time.valueOf("00:00:00"), t);
                }
            }
            return true;

        }
        case Types.TIMESTAMP: {
            Timestamp ts = rs.getTimestamp(1);
            boolean wn = rs.wasNull();
            if (wn)
                assertNull(rs.getTimestamp(1));
            else
            {
                if ( DATE_METHOD_NAME.equals(method) )
                {
                    assertEquals( (new java.sql.Timestamp( DATE_SEED )).toString(), ts.toString() );
                }
                else if ( CALENDAR_METHOD_NAME.equals(method) )
                {
                    assertEquals( (new java.sql.Timestamp( CALENDAR_SEED )).toString(), ts.toString() );
                }
                else
                {
                    assertEquals(Timestamp.valueOf("2004-02-14 00:00:00.0"), ts);
                }
            }
            return true;
        }
        case Types.CLOB: {
            Clob clob = rs.getClob(1);
            boolean wn = rs.wasNull();
            if (wn)
               assertNull(clob);
            else {
                char[] charray = new char[20];
                int numchar = clob.getCharacterStream().read(charray);
                String s = new String(charray,0,numchar);
                if ("setString".equals(method))
                    assertEquals("98",s);
                else if ("setAsciiStream".equals(method))
                    assertEquals("eg012d", s);
                else if ("setCharacterStream".equals(method))
                    assertEquals("89",s);
                else if ("setClob".equals(method))
                    assertEquals("72",s);
                else if ("setObject(java.lang.String)".equals(method))
                    assertEquals("98",s);
                else if ("setObject(java.lang.Clob)".equals(method))
                    assertEquals("72",s);
            }
            return true;
        }
        case Types.BLOB: {
            Blob blob = rs.getBlob(1);
            boolean wn = rs.wasNull();
            if (wn)
              assertNull(blob);
            else {
                assertEquals("0x4,0x3", showFirstTwo(blob.getBinaryStream())); 
            }
            return true;
        }
        case Types.BOOLEAN: {
            boolean b = rs.getBoolean(1);
            boolean wn = rs.wasNull();
            if (wn) {
                assertFalse(b);
            } else {
                assertTrue(b);
            }
            return true;
        }
        default:
            fail("FAIL JDBC TYPE IN getValidValue "
                    + JDBC.sqlNameFromJdbc(jdbcType));
            return false;
        }
    }

    private static void checkValidStringValue(String method, String s) {
        s = s.trim();
        if (isBooleanMethod(method))
            assertEquals("true", s);
        else if ("setBytes".equals(method) ||
                ("setObject(byte[])".equals(method)))
            assertEquals("EncodedString: > 1027 ",s.substring(0,22));
        else if ("setFloat".equals(method))
            assertEquals("98.4", s);
        else if ("setDouble".equals(method))
            assertEquals("98.5",s);
        else if ("setDate".equals(method) ||
                "setObject(java.sql.Date)".equals(method))
            assertEquals("2004-02-14", s);
        else if ("setTime".equals(method) ||
                "setObject(java.sql.Time)".equals(method))
            assertEquals("00:00:00",s);
        else if ("setTimestamp".equals(method)||
                "setObject(java.sql.Timestamp)".equals(method))
            assertEquals("2004-02-14 00:00:00.0",s);
        else if ("setAsciiStream".equals(method))
            assertEquals("eg012d",s);
        else if ("setCharacterStream".equals(method))
            assertEquals("89",s);
        else if ("setObject(java.lang.Float)".equals(method) ||
                "setObject(java.lang.Double)".equals(method))
               assertEquals("98.0",s);
        else if ( DATE_METHOD_NAME.equals(method))
            assertEquals( ( new java.sql.Timestamp( DATE_SEED ) ).toString(), s );
        else if ( CALENDAR_METHOD_NAME.equals(method))
            assertEquals( ( new java.sql.Timestamp( CALENDAR_SEED ) ).toString(), s );
        else
            assertEquals("98",s.trim());
    }

    private static boolean isBooleanMethod(String method) {
        return method.equals("setBoolean")
                || method.equals("setObject(java.lang.Boolean)");
    }

    private static boolean getOutValue(CallableStatement cs, int param,
            int regJdbcType, int paramType) throws SQLException, IOException {
        
        int paramJdbcType= jdbcTypes[paramType];
        switch (regJdbcType) {
        case Types.BIT:
        case Types.BOOLEAN:
        {
            boolean val = cs.getBoolean(param);
            boolean wn = cs.wasNull();
            if (!wn)
                assertTrue(val);

            return true;
        }
        case Types.TINYINT: {
            // Check out and inout params for procedures
            byte val = cs.getByte(param);
            boolean wn = cs.wasNull();
            if (!wn)
                checkProcedureOutput(param, paramType, val);
            return true;
        }
            
        case Types.SMALLINT: {
            short val = cs.getShort(param);
            boolean wn = cs.wasNull();
            if (!wn)
                checkProcedureOutput(param, paramType, val);
            return true;
        }
    case Types.INTEGER: {
            int val = cs.getInt(param);
            boolean wn = cs.wasNull();
            if (!wn)
                checkProcedureOutput(param, paramType, val);
            return true;
    }
        case Types.BIGINT: {
            long val = cs.getLong(param);
            boolean wn = cs.wasNull();
            if(!wn)
                checkProcedureOutput(param, paramType, val);
            return true;
        }
        case Types.REAL: {
            float val = cs.getFloat(param);
            boolean wn = cs.wasNull();
            if(!wn)
                checkProcedureOutput(param, paramType, val);
            return true;
        }
        case Types.FLOAT:
        case Types.DOUBLE: {
            double val = cs.getDouble(param);
            boolean wn = cs.wasNull();
            if (!wn)
                checkProcedureOutput(param, paramType, val);
            return true;
        }       
        case Types.DECIMAL: {
           String val = BigDecimalHandler.getBigDecimalString(cs, param, regJdbcType);
           boolean wn = cs.wasNull();
           if (!wn)
               checkProcedureOutput(param,paramType,val);
           return true;
        }
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR: {
            String val = cs.getString(param);
            boolean wn = cs.wasNull();
            if (!wn)
                checkProcedureOutput(param,paramType,val.trim());
            return true;
        }
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY: {
            byte[] data = cs.getBytes(param);
            boolean wn = cs.wasNull();
            if (!wn)
                checkProcedureOutput(param,paramType,data);
            return true;
        }

        case Types.DATE: {
            Date val = cs.getDate(param);
            boolean wn = cs.wasNull();
            if (!wn)
                checkProcedureOutput(param,paramType,val);            
            return true;
        }
        case Types.TIME: {
            Time val = cs.getTime(param);
            boolean wn = cs.wasNull();
            if (!wn)
                checkProcedureOutput(param,paramType,val);
            return true;
        }
        case Types.TIMESTAMP: {
            Timestamp val = cs.getTimestamp(param);
            boolean wn = cs.wasNull();
            if (!wn)
                checkProcedureOutput(param,paramType,val);
            return true;
        }
        case Types.CLOB: {
            // clob not allowed for procedures
            Clob clob = cs.getClob(param);
            boolean wn = cs.wasNull();
            return true;
        }
        case Types.BLOB: {
            // blob not allowed for procedures
            Blob blob = cs.getBlob(param);
            boolean wn = cs.wasNull();
            return true;
        }
        default:
            fail("FAIL JDBC TYPE IN getOutValue "
                    + JDBC.sqlNameFromJdbc(regJdbcType));
            return false;
        }
    }

    private static void checkProcedureOutput(int param, int paramType, byte val)
    {
        checkProcedureOutput(param,paramType,(long) val);
    }
    
    private static void checkProcedureOutput(int param, int paramType, short val)
    {
        checkProcedureOutput(param,paramType,(long) val);
    }

    
    private static void checkProcedureOutput(int param, int paramType, int val)
    {
        checkProcedureOutput(param,paramType,(long) val);
    }

    
    private static void checkProcedureOutput(int param, int paramType, long val) {
        switch (jdbcTypes[paramType]) {
        case java.sql.Types.SMALLINT:
           if (param == 2)
               assertEquals(38,val);
           else if (param == 3)
               assertEquals(77,val);
           break;
        case java.sql.Types.INTEGER:
            if (param == 2)
                assertEquals(41,val);
            else if (param == 3)
                assertEquals(88,val);
        break;
        case java.sql.Types.BIGINT:
            if (param == 2)
                assertEquals(40,val);
            else if (param == 3)
                assertEquals(99,val);
            break;
        case java.sql.Types.FLOAT:
            if (param == 2)
                assertEquals(35,val);
            else if (param == 3)
                assertEquals(66,val);
            break;
        case java.sql.Types.REAL:
            if (param == 2)
                assertEquals(41,val);
            else if (param == 3)
                assertEquals(88,val);
            break;
        case java.sql.Types.DECIMAL:
            if (param == 2)
                assertEquals(34,val);
            else if (param == 3)
                assertEquals(84,val);
            break;
        case java.sql.Types.DOUBLE:
            if (param == 2)
                assertEquals(35,val);
            else if (param == 3)
                assertEquals(66,val);
            break;
        }
    }
    
    private static void checkProcedureOutput(int param, int paramType, float val) {
        checkProcedureOutput(param,paramType, (double) val);
    }
    
    private static void checkProcedureOutput(int param, int paramType, double val) {
        switch (jdbcTypes[paramType]) {
        case java.sql.Types.SMALLINT:
           if (param == 2)
               assertEquals(38.0,val,.00001);
           else if (param == 3)
               assertEquals(77.0,val,.00001);
           break;
        case java.sql.Types.INTEGER:
            if (param == 2)
                assertEquals(41.0,val,.00001);
            else if (param == 3)
                assertEquals(88.0,val, .00001);
        break;
        case java.sql.Types.BIGINT:
            if (param == 2)
                assertEquals(40.0,val,.00001);
            else if (param == 3)
                assertEquals(99.0,val,.00001);
            break;
        case java.sql.Types.FLOAT:
            if (param == 2)
                assertEquals(35.9,val,.00001);
            else if (param == 3)
                assertEquals(66.8,val,.00001);
            break;
        case java.sql.Types.REAL:
            if (param == 2)
                assertEquals(41.9,val,.00001);
            else if (param == 3)
                assertEquals(88.8,val,.00001);
            break;
        case java.sql.Types.DECIMAL:
            if (param == 2)
                assertEquals(34.29999,val,.0001);
            else if (param == 3)
                assertEquals(84.09999,val,.0001);
            break;
        case java.sql.Types.DOUBLE:
            if (param == 2)
                assertEquals(35.9,val,.00001);
            else if (param == 3)
                assertEquals(66.8,val,.00001);
            break;
        }
    }

    
    private static void checkProcedureOutput(int param, int paramType, String val) {
        switch (jdbcTypes[paramType]) {
        case java.sql.Types.SMALLINT:
           if (param == 2)
               assertEquals("38",val);
           
           else if (param == 3)
               assertEquals("77",val);
           break;
        case java.sql.Types.INTEGER:
            if (param == 2)
                assertEquals("41",val);
            else if (param == 3)
                assertEquals("88",val);
        break;
        case java.sql.Types.BIGINT:
            if (param == 2)
                assertEquals("40",val);
            else if (param == 3)
                assertEquals("99",val);
            break;
        case java.sql.Types.FLOAT:
            if (param == 2)
                assertEquals("35.9",val);
            else if (param == 3)
                assertEquals("66.8",val);
            break;
        case java.sql.Types.REAL:
            if (param == 2)
                assertEquals("41.9",val);
            else if (param == 3)
                assertEquals("88.8",val);
            break;
        case java.sql.Types.DECIMAL:
            if (param == 2)
                assertEquals("34.29999",val);
            else if (param == 3)
                assertEquals("84.09999",val);
            break;
        case java.sql.Types.DOUBLE:
            if (param == 2)
                assertEquals("35.9",val);
            else if (param == 3)
                assertEquals("66.8",val);
            break;
        }
    }

    private static void checkProcedureOutput(int param, int paramType, byte[] val) {
        boolean isBlob =  ( jdbcTypes[ paramType ] == Types.BLOB );
        if (param == 2)
        {
            if ( isBlob )
            {
                assertEquals("0x82,0x43",showFirstTwo(val));
            }
            else
            {
                assertEquals("0x4,0x3",showFirstTwo(val));
            }
        }
        else if (param == 3)
        {
            if ( isBlob )
            {
                assertEquals("0x1,0x2",showFirstTwo(val));
            }
            else
            {
                assertEquals("0x9,0xfe",showFirstTwo(val));
            }
        }
    }
    
    private static void checkProcedureOutput(int param, int paramType, Date val) {
        switch (jdbcTypes[paramType]) {
        case java.sql.Types.DATE:
            if (param == 2)
                assertEquals("2004-03-08", val.toString());
            else if (param == 3)
                assertEquals("2005-03-08", val.toString());
            break;
        case java.sql.Types.TIMESTAMP:
            if (param == 2)
                assertEquals("2004-03-12", val.toString());
            else if (param == 3)
                assertEquals("2004-04-12", val.toString());
            break;
        }
    }
    
    private static void checkProcedureOutput(int param, int paramType, Time val) {
        switch (jdbcTypes[paramType]) {
        case java.sql.Types.TIME:
            if (param == 2)
                assertEquals("19:44:42", val.toString());
            else if (param == 3)
                assertEquals("20:44:42", val.toString());
            break;
        case java.sql.Types.TIMESTAMP:
            if (param == 2)
                assertEquals("21:14:24", val.toString());
            else if (param == 3)
                assertEquals("04:25:26", val.toString());
            break;
        }
    }
    private static void checkProcedureOutput(int param, int paramType, Timestamp val) {
        switch (jdbcTypes[paramType]) {
        case java.sql.Types.DATE:
            if (param == 2)
                assertEquals("2004-03-08 00:00:00.0",val.toString());
            else if (param == 3)
                assertEquals("2005-03-08 00:00:00.0", val.toString());
            break;
        case java.sql.Types.TIME:
            // getTimestamp on time will use the current date, so can't check it explicitly
            // just check not null  
            assertNotNull(val);
            break;
        case java.sql.Types.TIMESTAMP:
            if (param == 2)
                assertEquals("2004-03-12 21:14:24.938222433", val.toString());
            else if (param == 3)
                assertEquals("2004-04-12 04:25:26.462983731", val.toString());
           break;
        }
    }

    static void dumpSQLExceptions(SQLException se) {

        while (se != null) {
            System.out.println("SQLSTATE(" + se.getSQLState() + "): "
                    + se.toString());
            se = se.getNextException();
        }
    }

    /**
     * Test for DERBY-149 fix Check that setString to an invalid value throws an
     * exception rather than causing a hang
     * 
     * @param type
     *            type for SQLTypes array
     * @param psi -
     *            insert prepared statement.
     * 
     */
    private static void testSetStringInvalidValue(int type,
            PreparedStatement psi) {
        // Do not perform this test for string types.
        // Only test for types wich will fail with setString("InvalidValue");
        switch (jdbcTypes[type]) {
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
        case Types.CLOB:
            return;
        }

        String sqlType = SQLTypes[type];
        try {
            psi.setString(1, "Invalid Value");
            psi.executeUpdate();
            // Should have gotten exception. Test fails
            String error = "FAIL - setString(1,\"Invalld Value\") for type "
                    + sqlType + " did not throw an exception as expected";
        } catch (SQLException sqle) {

            if ("22018".equals(sqle.getSQLState())
                    || "XCL12".equals(sqle.getSQLState())
                    || "22007".equals(sqle.getSQLState())
                    || "22005".equals(sqle.getSQLState())
                    || (sqle.getMessage().indexOf("Invalid data conversion") != -1)
                    || (sqle.getMessage().indexOf("Illegal Conversion") != -1))
                ;
            // System.out.println(" IC (Expected)");
            else
                fail("FAIL:" + sqle.getMessage());
        } catch (Exception e) {
            fail("FAIL: Unexpected Exception " + e.getMessage());
        }
    }

    private static String showFirstTwo(java.io.Reader in)
            throws java.io.IOException {

        int b1 = in.read();
        int b2 = in.read();
        in.close();

        return "0x" + Integer.toHexString(b1) + "," + "0x"
                + Integer.toHexString(b2);
    }

    private static String showFirstTwo(java.io.InputStream in)
            throws java.io.IOException {

        int b1 = in.read();
        int b2 = in.read();
        in.close();

        return "0x" + Integer.toHexString(b1) + "," + "0x"
                + Integer.toHexString(b2);
    }

    private static String showFirstTwo(byte[] data) {

        int b1 = data[0];
        int b2 = data[1];

        return "0x" + Integer.toHexString(((int) b1) & 0xff) + "," + "0x"
                + Integer.toHexString(((int) b2) & 0xff);
    }
    
    public static Test suite() {
        
        return TestConfiguration.defaultSuite(ParameterMappingTest.class);
    }
        /*
        ** Procedures for parameter mapping testing.
        */

        public static void pmap(short in, short[] inout, short[] out) {

                inout[0] += 6;
                out[0] = 77;
        }
        public static void pmap(int in, int[] inout, int[] out) {
                inout[0] += 9;
                out[0] = 88;

        }
        public static void pmap(boolean in, boolean[] inout, boolean[] out) {
            inout[0] = true;
            out[0] = true;
        }
        public static void pmap(long in, long[] inout, long[] out) {
                inout[0] += 8;
                out[0] = 99;
        }
        public static void pmap(float in, float[] inout, float[] out) {
                inout[0] += 9.9f;
                out[0] = 88.8f;
        }
        public static void pmap(double in, double[] inout, double[] out) {
                inout[0] += 3.9;
                out[0] = 66.8;
        }
        public static void pmap(byte[] in, byte[][] inout, byte[][] out) {

                inout[0][2] = 0x56;
                out[0] = new byte[4];
                out[0][0] = (byte) 0x09;
                out[0][1] = (byte) 0xfe;
                out[0][2] = (byte) 0xed;
                out[0][3] = (byte) 0x02;

        }
        public static void pmap(Date in, Date[] inout, Date[] out) {

                inout[0] = java.sql.Date.valueOf("2004-03-08");
                out[0] = java.sql.Date.valueOf("2005-03-08");

        }
        public static void pmap(Time in, Time[] inout, Time[] out) {
                inout[0] = java.sql.Time.valueOf("19:44:42");
                out[0] = java.sql.Time.valueOf("20:44:42");
        }
        public static void pmap(Timestamp in, Timestamp[] inout, Timestamp[] out) {

                inout[0] = java.sql.Timestamp.valueOf("2004-03-12 21:14:24.938222433");
                out[0] = java.sql.Timestamp.valueOf("2004-04-12 04:25:26.462983731");
        }
        public static void pmap(String in, String[] inout, String[] out) {
                inout[0] = inout[0].trim().concat("P2-PMAP");
                out[0] = "P3-PMAP";
        }

        /*
        ** Procedure which uses BigDecimal - for parameter mapping testing.
        */

        public static void pmap(BigDecimal in, BigDecimal[] inout, BigDecimal[] out) {
                inout[0] = inout[0].add(new BigDecimal(2.3));
                out[0] = new BigDecimal(84.1);
        }

    /*
    ** Procedures which use LOBs - for parameter mapping testing.
    */

    public static void pmap(Blob in, Blob[] inout, Blob[] out) throws SQLException {
        int    leftLength = (int) in.length();
        int    rightLength = (int) inout[0].length();
        byte[] left = in.getBytes( 1L, leftLength );
        byte[] right = inout[0].getBytes( 1L, rightLength );
        byte[] retval = new byte[ leftLength + rightLength ];
        System.arraycopy( left, 0, retval, 0, leftLength );
        System.arraycopy( right, 0, retval, leftLength, rightLength );
        inout[0] = new HarmonySerialBlob( retval );
        
        out[0] = new HarmonySerialBlob( new byte[] { (byte) 1, (byte) 2, (byte) 3 } );
    }

    public static void pmap(Clob in, Clob[] inout, Clob[] out) throws SQLException {
        inout[0] = new HarmonySerialClob( in.getSubString( 1L, (int) in.length() ) + inout[0].getSubString( 1L, (int) inout[0].length() ) );
        out[0] = new HarmonySerialClob( "abc" );
    }

    //
    // Clob procs
    //
    
    public static void clobIn( Clob c, String[] result ) throws SQLException
    {
        result[ 0 ] = getClobValue( c );
    }
    public static void clobOut( Clob[] c ) throws SQLException
    {
        c[ 0 ] = new HarmonySerialClob( "abc" );
    }
    public static void clobInOut( Clob[] c ) throws SQLException
    {
        String value = getClobValue( c[ 0 ] );
        
        char[] inValue = value.toCharArray();
        char[] outValue = reverse( inValue );

        c[ 0 ] = new HarmonySerialClob( new String( outValue ) );
    }

    private static String getClobValue( Clob c ) throws SQLException
    {
        return c.getSubString( 1L, (int) c.length() );
    }
    private static char[] reverse( char[] in )
    {
        int count = in.length;

        char[] retval = new char[ count ];
        for ( int i = 0; i < count; i++ ) { retval[ i ] = in[ (count - i) - 1 ]; }

        return retval;
    }
    
    //
    // Blob procs
    //
    
    public static void blobIn( Blob c, String[] result ) throws Exception
    {
        result[ 0 ] = getBlobValue( c );
    }
    public static void blobOut( Blob[] c ) throws Exception
    {
        c[ 0 ] = new HarmonySerialBlob( "abc".getBytes( UTF8 ) );
    }
    public static void blobInOut( Blob[] c ) throws Exception
    {
        String value = getBlobValue( c[ 0 ] );
        
        char[] inValue = value.toCharArray();
        char[] outValue = reverse( inValue );

        c[ 0 ] = new HarmonySerialBlob( (new String( outValue )).getBytes( UTF8 ) );
    }

    private static String getBlobValue( Blob c ) throws Exception
    {
        byte[] bytes = c.getBytes( 1L, (int) c.length() );

        return new String( bytes, UTF8 );
    }
    
    //
    // Debug helpers
    //
    
    /**
     * Prepare a statement and report its sql text.
     */
    protected PreparedStatement   chattyPrepare( Connection conn, String text )
        throws SQLException
    {
        println( "Preparing statement:\n\t" + text );
        
        return conn.prepareStatement( text );
    }
    /**
     * Prepare a call statement and report its sql text.
     */
    protected CallableStatement   chattyPrepareCall( Connection conn, String text )
        throws SQLException
    {
        println( "Preparing statement:\n\t" + text );
        
        return conn.prepareCall( text );
    }

    /**
     * Assert that the statement text, when compiled, raises an exception
     */
    protected void    expectCompilationError( String sqlState, String query )
    {
        println( "\nExpecting " + sqlState + " when preparing:\n\t" + query );

        assertCompileError( sqlState, query );
    }

    /**
     * Tests that SQLStates are correct across drivers on rs.getXXX
     * over/underflow.
     * @exception SQLException database access error. Causes test to
     *                         fail with an error.
     */
    public void testDerby5533GetXXX() throws SQLException
    {
        String createTableString = "CREATE TABLE MultiTypeTable (" +
            "F01 SMALLINT," +
            "F02 INTEGER," +
            "F03 BIGINT," +
            "F04 REAL," +
            "F05 FLOAT," +
            "F06 DOUBLE," +
            "F07 DECIMAL(31)," +
            "F08 NUMERIC," +
            "F09 CHAR(100)," +
            "F10 VARCHAR(256)," +
            "F11 BOOLEAN)";
        Statement stmt = createStatement();
        stmt.executeUpdate(createTableString);

        PreparedStatement ps = prepareStatement
            ("insert into MultiTypeTable values(?,?,?,?,?,?,?,?,?,?,?)");

        /* First check upper bounds */

        ps.setShort(1, (short)((short)Byte.MAX_VALUE + 1));
        ps.setInt(2, (int)Short.MAX_VALUE + 1);
        ps.setLong(3, (long)Integer.MAX_VALUE + 1);
        ps.setFloat(4, (float)Long.MAX_VALUE * 10);
        ps.setFloat(5, (float)Long.MAX_VALUE * 10);
        ps.setDouble(6, (double)Float.MAX_VALUE * 10);
        // Largest integer representable in DECIMAL is Derby has 31 digits:
        ps.setBigDecimal(7, new BigDecimal("9999999999999999999999999999999"));
        ps.setInt(8, _X);
        ps.setString(9, " ");
        ps.setString(10, " ");
        ps.setBoolean(11, true);
        ps.executeUpdate();

        PreparedStatement plainSelect = 
                prepareStatement("select * from MultiTypeTable");
        ResultSet rs = plainSelect.executeQuery();
        rs.next();

        // JDBC type -> byte
        assertGetState(rs, "F01", XXX_BYTE, "22003");
        assertGetState(rs, "F02", XXX_BYTE, "22003");
        assertGetState(rs, "F03", XXX_BYTE, "22003");
        assertGetState(rs, "F04", XXX_BYTE, "22003");
        assertGetState(rs, "F05", XXX_BYTE, "22003");
        assertGetState(rs, "F06", XXX_BYTE, "22003");
        assertGetState(rs, "F07", XXX_BYTE, "22003");

        // JDBC type -> short
        assertGetState(rs, "F02", XXX_SHORT, "22003");
        assertGetState(rs, "F03", XXX_SHORT, "22003");
        assertGetState(rs, "F04", XXX_SHORT, "22003");
        assertGetState(rs, "F05", XXX_SHORT, "22003");
        assertGetState(rs, "F06", XXX_SHORT, "22003");
        assertGetState(rs, "F07", XXX_SHORT, "22003");

        // JDBC type -> int
        assertGetState(rs, "F03", XXX_INT, "22003");
        assertGetState(rs, "F04", XXX_INT, "22003");
        assertGetState(rs, "F05", XXX_INT, "22003");
        assertGetState(rs, "F06", XXX_INT, "22003");
        assertGetState(rs, "F07", XXX_INT, "22003");

        // JDBC type -> long
        assertGetState(rs, "F04", XXX_LONG, "22003");
        assertGetState(rs, "F05", XXX_LONG, "22003");
        assertGetState(rs, "F06", XXX_LONG, "22003");
        assertGetState(rs, "F07", XXX_LONG, "22003");
        rs.close();


        // JDBC type -> float
        PreparedStatement uSelect = prepareStatement(
            "SELECT * FROM MultiTypeTable",
            ResultSet.TYPE_FORWARD_ONLY,
            ResultSet.CONCUR_UPDATABLE);
        rs = uSelect.executeQuery();
        rs.next();
        rs.updateDouble("F06", Float.MAX_VALUE * 10.0);
        rs.updateRow();

        rs = plainSelect.executeQuery();
        rs.next();

        assertGetState(rs, "F06", XXX_FLOAT, "22003");


        /* Now check lower bounds */
        PreparedStatement psDelete = prepareStatement(
                "delete from MultiTypeTable");
        psDelete.executeUpdate();

        ps.setShort(1, (short)((short)Byte.MIN_VALUE - 1));
        ps.setInt(2, (int)Short.MIN_VALUE - 1);
        ps.setLong(3, (long)Integer.MIN_VALUE - 1);
        ps.setFloat(4, -(float)Long.MAX_VALUE * 10);
        ps.setFloat(5, -(float)Long.MAX_VALUE * 10);
        ps.setDouble(6, -(double)Float.MAX_VALUE * 10);
        // Largest integer representable in DECIMAL is Derby has 31 digits:
        ps.setBigDecimal(7, new BigDecimal("-999999999999999999999999999999"));
        ps.setInt(8, _X);
        ps.setString(9, " ");
        ps.setString(10, " ");
        ps.setBoolean(11, false);
        ps.executeUpdate();

        rs = plainSelect.executeQuery();

        rs.next();
        // JDBC type -> byte
        assertGetState(rs, "F01", XXX_BYTE, "22003");
        assertGetState(rs, "F02", XXX_BYTE, "22003");
        assertGetState(rs, "F03", XXX_BYTE, "22003");
        assertGetState(rs, "F04", XXX_BYTE, "22003");
        assertGetState(rs, "F05", XXX_BYTE, "22003");
        assertGetState(rs, "F06", XXX_BYTE, "22003");
        assertGetState(rs, "F07", XXX_BYTE, "22003");

        // JDBC type -> short
        assertGetState(rs, "F02", XXX_SHORT, "22003");
        assertGetState(rs, "F03", XXX_SHORT, "22003");
        assertGetState(rs, "F04", XXX_SHORT, "22003");
        assertGetState(rs, "F05", XXX_SHORT, "22003");
        assertGetState(rs, "F06", XXX_SHORT, "22003");
        assertGetState(rs, "F07", XXX_SHORT, "22003");

        // JDBC type -> int
        assertGetState(rs, "F03", XXX_INT, "22003");
        assertGetState(rs, "F04", XXX_INT, "22003");
        assertGetState(rs, "F05", XXX_INT, "22003");
        assertGetState(rs, "F06", XXX_INT, "22003");
        assertGetState(rs, "F07", XXX_INT, "22003");

        // JDBC type -> long
        assertGetState(rs, "F04", XXX_LONG, "22003");
        assertGetState(rs, "F05", XXX_LONG, "22003");
        assertGetState(rs, "F06", XXX_LONG, "22003");

        // JDBC type -> float
        rs.close();

        rs = uSelect.executeQuery();
        rs.next();
        rs.updateDouble("F06", -Float.MAX_VALUE * 10.0);
        rs.updateRow();

        rs = plainSelect.executeQuery();
        rs.next();

        assertGetState(rs, "F06", XXX_FLOAT, "22003");
    }


    /**
     * Tests that SQLStates are correct across drivers on updateXXX
     * over/underflow.
     * @exception SQLException database access error. Causes test to
     *                         fail with an error.
     */
    public void testDerby5533UpdateXXX() throws SQLException
    {
        String createTableString = "CREATE TABLE MultiTypeTable (" +
            "F01 SMALLINT," +
            "F02 INTEGER," +
            "F03 BIGINT," +
            "F04 REAL," +
            "F05 FLOAT," +
            "F06 DOUBLE," +
            "F07 DECIMAL(31)," +
            "F08 NUMERIC," +
            "F09 CHAR(100)," +
            "F10 VARCHAR(256)," +
            "F11 BOOLEAN)";
        Statement stmt = createStatement();
        stmt.executeUpdate(createTableString);

        PreparedStatement ps = prepareStatement
            ("insert into MultiTypeTable values(?,?,?,?,?,?,?,?,?,?,?)");
        PreparedStatement psDelete = prepareStatement(
            "delete from MultiTypeTable");

        /* First check upper bounds */

        ps.setShort(1, (short)1);
        ps.setInt(2, 1);
        ps.setLong(3, 1L);
        ps.setFloat(4, 1.0f);
        ps.setDouble(5, 1.0);
        ps.setDouble(6, 1.0);
        ps.setString(7, "1");
        ps.setString(8, "1");
        ps.setString(9, "1");
        ps.setString(10, "1");
        ps.setBoolean(11, true);

        ps.executeUpdate();

        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY,
                ResultSet.CONCUR_UPDATABLE);
        ResultSet rs = s.executeQuery("SELECT * FROM MultiTypeTable");
        rs.next();

        // SMALLINT
        assertUpdateState(rs, "F01",
                          Short.MAX_VALUE + 1, _X, XXX_INT,"22003");
        assertUpdateState(rs, "F01",
                          _X, Short.MAX_VALUE + 1, XXX_DOUBLE, "22003");
        assertUpdateState(rs, "F01",
                          Short.MAX_VALUE + 1, _X, XXX_LONG, "22003");
        assertUpdateState(rs, "F01",
                          _X, Short.MAX_VALUE + 1, XXX_FLOAT, "22003");
        assertUpdateState(rs, "F01",
                          bdMaxShortValue.add(BigDecimal.ONE), "22003");

        assertUpdateState(rs, "F01",
                          Short.MIN_VALUE - 1, _X, XXX_INT,"22003");
        assertUpdateState(rs, "F01",
                          _X, Short.MIN_VALUE - 1, XXX_DOUBLE, "22003");
        assertUpdateState(rs, "F01",
                          Short.MIN_VALUE - 1, _X, XXX_LONG, "22003");
        assertUpdateState(rs, "F01",
                          _X, Short.MIN_VALUE - 1, XXX_FLOAT, "22003");
        assertUpdateState(rs, "F01",
                          bdMinShortValue.subtract(BigDecimal.ONE), "22003");


        // INT
        assertUpdateState(rs, "F02",
                          (long)Integer.MAX_VALUE + 1, _X, XXX_LONG, "22003");
        assertUpdateState(rs, "F02", _X,
                          (float)Integer.MAX_VALUE * 10, XXX_FLOAT, "22003");
        assertUpdateState(rs, "F02", _X,
                          (double)Integer.MAX_VALUE * 10, XXX_DOUBLE, "22003");
        assertUpdateState(rs, "F02",
                          bdMaxIntValue.add(BigDecimal.ONE), "22003");

        assertUpdateState(rs, "F02",
                          (long)Integer.MIN_VALUE - 1, _X, XXX_LONG, "22003");
        assertUpdateState(rs, "F02",
                       _X, (float)Integer.MIN_VALUE * 10, XXX_FLOAT, "22003");
        assertUpdateState(rs, "F02",
                       _X, (double)Integer.MIN_VALUE * 10, XXX_DOUBLE, "22003");
        assertUpdateState(rs, "F02",
                          bdMinIntValue.subtract(BigDecimal.ONE), "22003");

        // BIGINT
        assertUpdateState(rs, "F03",
                          _X, (float)Long.MAX_VALUE * 10, XXX_FLOAT, "22003");
        assertUpdateState(rs, "F03",
                          _X, (double)Long.MAX_VALUE * 10, XXX_DOUBLE, "22003");
        assertUpdateState(rs, "F03",
                          bdMaxLongValue.add(BigDecimal.ONE), "22003");

        assertUpdateState(rs, "F03",
                          _X, (float)Long.MIN_VALUE * 10, XXX_FLOAT, "22003");
        assertUpdateState(rs, "F03",
                          _X, (double)Long.MIN_VALUE * 10, XXX_DOUBLE, "22003");
        assertUpdateState(rs, "F03",
                          bdMinLongValue.subtract(BigDecimal.ONE), "22003");

        // REAL overflow checking
        Float maxF = Float.MAX_VALUE;
        assertUpdateState(rs, "F04",
                          _X, maxF.doubleValue() * 10,
                          XXX_DOUBLE, "22003");
        assertUpdateState(rs, "F04",
                          _X, Float.NEGATIVE_INFINITY, XXX_FLOAT, "22003");
        assertUpdateState(rs, "F04",
                          bdMaxFloatValue.multiply(BigDecimal.TEN), "22003");

        assertUpdateState(rs, "F04",
                          _X, -(maxF).doubleValue() * 10,
                          XXX_DOUBLE, "22003");
        assertUpdateState(rs, "F04",
                          _X, Float.POSITIVE_INFINITY, XXX_FLOAT, "22003");
        assertUpdateState(rs, "F04",
                          _X, Float.NEGATIVE_INFINITY, XXX_FLOAT, "22003");
        assertUpdateState(rs, "F04",
                          bdMinFloatValue.multiply(BigDecimal.TEN), "22003");

        // These two would fail prior to DERBY-3398
        assertUpdateOK(rs, "F04", _X, Float.MIN_VALUE, XXX_FLOAT);
        assertUpdateOK(rs, "F04", _X, -Float.MIN_VALUE, XXX_FLOAT);

        // Make unconditional when DERBY-5534 is fixed
        if (usingEmbedded()) {
            assertUpdateState(rs, "F04",
                              _X, Float.NaN, XXX_FLOAT, "22003");
            assertUpdateState(rs, "F04",
                              _X, Double.MIN_VALUE, XXX_DOUBLE, "22003");
            assertUpdateState(rs, "F04",
                              _X, -Double.MIN_VALUE, XXX_DOUBLE, "22003");
        }

        // REAL Underflow checking
        // Make unconditional DERBY-5534 is fixed
        if (usingEmbedded()) {
            assertUpdateState(rs, "F04", bdSmallestPosDoubleValue, "22003");
            assertUpdateState(rs, "F04", bdSmallestNegDoubleValue, "22003");
        }

        // DOUBLE, FLOAT (SQL FLOAT is really the same as SQL DOUBLE in Derby)
        final String[] dfCols = new String[]{"F05", "F06"};
        for (int i = 0; i < 2; i++) {
            assertUpdateState(rs, dfCols[i], _X,
                              Float.POSITIVE_INFINITY, XXX_FLOAT, "22003");
            assertUpdateState(rs, dfCols[i], _X,
                              Double.POSITIVE_INFINITY, XXX_DOUBLE, "22003");
            assertUpdateState(rs, dfCols[i],
                              bdMaxDoubleValue.multiply(BigDecimal.TEN),
                              "22003");

            assertUpdateState(rs, dfCols[i],
                              _X, Float.NEGATIVE_INFINITY, XXX_FLOAT, "22003");
            assertUpdateState(rs, dfCols[i],
                              _X, Double.NEGATIVE_INFINITY,
                              XXX_DOUBLE, "22003");
            assertUpdateState(rs, dfCols[i],
                              bdMinDoubleValue.multiply(BigDecimal.TEN),
                              "22003");

            // Make unconditional when DERBY-5534 is fixed
            if (usingEmbedded()) {
                assertUpdateState(rs, dfCols[i],
                                  _X, Double.NaN, XXX_DOUBLE, "22003");
            }

            // DOUBLE, FLOAT underflow checking
            // Make unconditional when DERBY-5534 is fixed
            if (usingEmbedded()) {
                assertUpdateState(rs, dfCols[i],
                    bdSmallestPosDoubleValue.divide(BigDecimal.TEN), "22003");
                assertUpdateState(rs, dfCols[i],
                    bdSmallestNegDoubleValue.divide(BigDecimal.TEN), "22003");
            }

            // These two would fail prior to DERBY-3398
            assertUpdateOK(rs, dfCols[i], _X, Double.MIN_VALUE, XXX_DOUBLE);
            assertUpdateOK(rs, dfCols[i], _X, -Double.MIN_VALUE, XXX_DOUBLE);
        }

        // Derby BOOLEAN: not range checked: FALSE of 0, else TRUE.
        // assertUpdateState(rs, "F11", 2, _X, XXX_BYTE, "22003");
        // assertUpdateState(rs, "F11", 2, _X, XXX_SHORT, "22003");
        // assertUpdateState(rs, "F11", 2, _X, XXX_INT, "22003");
        // assertUpdateState(rs, "F11", 2, _X, XXX_LONG, "22003");
        // assertUpdateState(rs, "F11", _X, 2.0, XXX_FLOAT, "22003");
        // assertUpdateState(rs, "F11", _X, 2.0, XXX_DOUBLE, "22003");
        // assertUpdateState(rs, "F11", new BigDecimal(2), "22003");
    }

    /**
     * DERBY-5536: client driver change of implementation for getting long
     * from DECIMAL, so check correctness for two cases: 1) value with 18
     * decimal digits or less, and 2) value with more than 18 decimal
     * digits. Reason: cross-over point in implementation; the smaller
     * numbers use an optimized code path.  Also try with and without
     * non-zero fraction to see what happens to the discarded fractional
     * part (scale == 1): Conversions to long should round off in the
     * direction of zero for both positive and negative numbers with a
     * fractional part &gt;&lt; 0, cf. RoundingMode.DOWN used in the asserts
     * below.
     */
    public void testDerby5536() throws SQLException {

        BigDecimal vBelow[] =
            new BigDecimal[]{new BigDecimal(123456789012345678L),  // 18 digits
                             new BigDecimal(-12345678901234567L)};

        BigDecimal vAbove[] =
            new BigDecimal[]{new BigDecimal(1234567890123456789L), // 19 digits
                             new BigDecimal(-123456789012345678L)};

        createStatement().executeUpdate(
            "create table t5536(d1 decimal(19,1)," +
            "                   d2 decimal(20,1)," +
            "                   i int generated always as identity" +
            "                         (start with 1, increment by 1))");
        PreparedStatement ps5536 = prepareStatement(
            "insert into t5536 values (?, ?, default)");

        for (int scale=0; scale < 2; scale++) {
            for (int i=0; i < vBelow.length; i++) {
                ps5536.setBigDecimal(
                    1,
                    new BigDecimal(vBelow[i].toBigInteger(), scale));
                ps5536.setBigDecimal(
                    2,
                    new BigDecimal(vAbove[i].toBigInteger(), scale));

                ps5536.execute();
            }
        }



        ResultSet rs = createStatement().executeQuery(
            "select * from t5536 order by i");

        BigDecimal divisor[] = {BigDecimal.ONE, BigDecimal.TEN};

        for (int scale=0; scale < 2; scale++) {
            for (int i=0; i < vBelow.length; i++) {
                rs.next();

                assertEquals(
                    "round-trip conversion error",
                    vBelow[i].divide(divisor[scale], RoundingMode.DOWN).
                        longValue(),
                    rs.getLong(1));
                assertEquals(
                    "round-trip conversion error",
                    vAbove[i].divide(divisor[scale], RoundingMode.DOWN).
                        longValue(),
                    rs.getLong(2));
            }
        }

        rs.close();
    }

    public void testDerby6902()
        throws SQLException
    {
        createStatement().executeUpdate(
            "create table test6902 (" +
            "  id bigint primary key," +
            "  big_number bigint not null," +
            "  small_number int not null" +
            ")" );

        PreparedStatement ps6902 = prepareStatement(
            "delete from test6902 " +
            "  where big_number < ? - small_number * 1000" );

        try {
            ps6902.setLong(1, 1470362049757L);
            ps6902.executeUpdate();
            fail("without cast, expected setLong to fail");
        } catch (SQLException e) {
            assertSQLState( "22003", e );
        }

        ps6902.setLong(1, 1479058636L); // value < Integer.MAX_VALUE
        ps6902.executeUpdate();

	// Use a cast on integer column small_number:

        ps6902 = prepareStatement(
            "delete from test6902 " +
            "  where big_number < " +
            "        ? - cast( small_number as bigint) * 1000" );

        ps6902.setLong(1, 1470362049757L);
        ps6902.executeUpdate();

	// Use a cast on the parameter marker itself:

        ps6902 = prepareStatement(
            "delete from test6902 " +
            "  where big_number < " +
            "        cast( ? as bigint) - small_number * 1000" );

        ps6902.setLong(1, 1470362049757L);
        ps6902.executeUpdate();

        try {
            ps6902.setString( 1,  "abcde" );
            ps6902.executeUpdate();
            fail("expected setString to fail with non-numeric string");
        } catch (SQLException e) {
            assertSQLState( "22018", e );
        }

        // Use setString to set integer values, both small and large,
        // into the statement using CAST to make the parameter BIGINT:

        ps6902.setString(1, "1479058636" ); // value < Integer.MAX_VALUE
        ps6902.executeUpdate();

        ps6902.setString(1, "1470362049757" );
        ps6902.executeUpdate();

        try {
            ps6902 = prepareStatement(
                "delete from test6902 where small_number * 1000 > ?" );
            ps6902.setLong( 1, 1470362049757L);
            ps6902.executeUpdate();
            fail("Expected out of range exception.");
        } catch (SQLException e) {
            assertSQLState( "22003", e );
        }

        // Algebraically re-formulate the original query:

        ps6902 = prepareStatement(
            "delete from test6902 " +
            "  where big_number + small_number * 1000 < ?" );
        ps6902.setLong( 1, 1470362049757L);
        ps6902.executeUpdate();

        // Without casts, use setString to set integer values,
        // small and large:

        ps6902 = prepareStatement(
            "delete from test6902 " +
            "  where big_number < ? - small_number * 1000" );

        ps6902.setString(1, "1479058636" ); // value < Integer.MAX_VALUE
        ps6902.executeUpdate();

        try {
            ps6902.setString(1, "1470362049757" );
            ps6902.executeUpdate();
            fail("expected setString to fail with numeric string > INT_MAX");
        } catch (SQLException e) {
            assertSQLState( "22018", e );
        }
    }

    // Short limits
    //
    private final static BigDecimal bdMaxShortValue =
        BigDecimal.valueOf(Short.MAX_VALUE);

    private final static BigDecimal bdMinShortValue =
        BigDecimal.valueOf(Short.MIN_VALUE);

    // Integer limits
    //
    private final static BigDecimal bdMaxIntValue =
        BigDecimal.valueOf(Integer.MAX_VALUE);

    private final static BigDecimal bdMinIntValue =
        BigDecimal.valueOf(Integer.MIN_VALUE);

    // Long limits
    //
    private final static BigDecimal bdMaxLongValue =
        BigDecimal.valueOf(Long.MAX_VALUE);

    private final static BigDecimal bdMinLongValue =
        BigDecimal.valueOf(Long.MIN_VALUE);

    // Float limits
    //
    private final static BigDecimal bdMaxFloatValue =
        new BigDecimal(Float.MAX_VALUE);

    private final static BigDecimal bdMinFloatValue =
        new BigDecimal(-Float.MAX_VALUE);

    private final static BigDecimal bdSmallestPosFloatValue =
        new BigDecimal(Float.MIN_VALUE);

    private final static BigDecimal bdSmallestNegFloatValue =
        new BigDecimal(-Float.MIN_VALUE);

    // Double limits
    //
    private final static BigDecimal bdMaxDoubleValue =
        new BigDecimal(Double.MAX_VALUE);

    private final static BigDecimal bdMinDoubleValue =
        new BigDecimal(-Double.MAX_VALUE);

    private final static BigDecimal bdSmallestPosDoubleValue =
        new BigDecimal(Double.MIN_VALUE);

    private final static BigDecimal bdSmallestNegDoubleValue =
        new BigDecimal(-Double.MIN_VALUE);

    // REAL/FLOAT/DOUBLE range limits

    static final float DB2_SMALLEST_REAL = -3.402E+38f;
    static final float DB2_LARGEST_REAL  = +3.402E+38f;
    static final float DB2_SMALLEST_POSITIVE_REAL = +1.175E-37f;
    static final float DB2_LARGEST_NEGATIVE_REAL  = -1.175E-37f;

    static final double DB2_SMALLEST_DOUBLE = -1.79769E+308d;
    static final double DB2_LARGEST_DOUBLE  = +1.79769E+308d;
    static final double DB2_SMALLEST_POSITIVE_DOUBLE = +2.225E-307d;
    static final double DB2_LARGEST_NEGATIVE_DOUBLE  = -2.225E-307d;

    // Constants for use with assertUpdateState and assertGetState

    private static final int _X = -1; // don't care
    private static final int XXX_BYTE = 0;
    private static final int XXX_SHORT = 1;
    private static final int XXX_INT = 2;
    private static final int XXX_LONG = 3;
    private static final int XXX_FLOAT = 4;
    private static final int XXX_DOUBLE = 5;

    /*
     * Using ResultSet.updateBigDecimal with value on colName, assert that we
     * see the SQLstate expected.
     */
    private void assertUpdateState(
        ResultSet rs,
        String colName,
        BigDecimal value,
        String expected) throws SQLException {

        try {
            rs.updateBigDecimal(colName, value);
            fail("exception expected");
        } catch (SQLException e) {
            println(e.toString());
            assertSQLState(expected, e);
        }
    }

    /*
     * Using ResultSet.updateXXX with value or dvalue as the case may be on
     * colName, assert that we do not see an error. XXX is indicated by
     * updateType.
     */
    private void assertUpdateOK(
            ResultSet rs,
            String colName,
            long value,
            double dvalue,
            int updateType) throws SQLException {
        assertUpdateState(rs, colName, value, dvalue, updateType, null);
    }
    /*
     * Using ResultSet.updateXXX with value or dvalue as the case may be on
     * colName, assert that we see the SQLstate expected. XXX is indicated by
     * updateType. If expected is null, expect no error.
     */
    private void assertUpdateState(
        ResultSet rs,
        String colName,
        long value,
        double dvalue,
        int updateType,
        String expected) throws SQLException {

        try {
            switch (updateType) {
            case XXX_BYTE:
                rs.updateByte(colName, (byte)value);
                break;
            case XXX_SHORT:
                rs.updateShort(colName, (short)value);
            case XXX_INT:
                rs.updateInt(colName, (int)value);
                break;
            case XXX_LONG:
                rs.updateLong(colName, value);
                break;
            case XXX_FLOAT:
                rs.updateFloat(colName, (float)dvalue);
                break;
            case XXX_DOUBLE:
                rs.updateDouble(colName, dvalue);
                break;
            default:
                fail("wrong argument");
            }

            if (expected != null) {
                fail("exception expected");
            }
        } catch (SQLException e) {
            if (expected == null) {
                throw e;
            }
            println(e.toString());
            assertSQLState(expected, e);
        }
    }


    /*
     * Using ResultSet.getXXX on colName, assert that we see the SQLstate
     * expected. XXX is indicated by getType.
     */
    private void assertGetState(
        ResultSet rs,
        String colName,
        int getType,
        String expected) throws SQLException {

        try {
            switch (getType) {
            case XXX_BYTE:
                rs.getByte(colName);
                break;
            case XXX_SHORT:
                rs.getShort(colName);
                    break;
            case XXX_INT:
                rs.getInt(colName);
                break;
            case XXX_LONG:
                rs.getLong(colName);
                break;
            case XXX_FLOAT:
                rs.getFloat(colName);
                break;
            case XXX_DOUBLE:
                rs.getDouble(colName);
                break;
            default:
                fail("wrong argument");
            }

            fail("exception expected");
        } catch (SQLException e) {
            println(e.toString());
            assertSQLState(expected, e);
        }
    }

	private static boolean compareClobReader2CharArray
		(char[] cArray, Reader charReader) throws Exception {
		char[] clobChars = new char[cArray.length];

		int readChars = 0;
		int totalCharsRead = 0;

		do {
			readChars = charReader.read(clobChars, totalCharsRead, cArray.length - totalCharsRead);
			if (readChars != -1) 
				totalCharsRead += readChars;
		} while (readChars != -1 && totalCharsRead < cArray.length);
		charReader.close();
		if (!java.util.Arrays.equals(cArray, clobChars)) {
			return false;
		}

		return true;
	}

    /**
     * DERBY-6237(PreparedStatement.execute() fails starting 10.2 when 
     *  multiple rows are updated and 
     *  PreparedStatement.setCharacterStream(int, Reader, int) is used)  
	 * Test setCharacterStream on CLOB column 
     */
	public void testUpdateSetCharacterStreamClob() throws Exception
    {
		helperTestClobOrVarchar(true);
    }
    
    /**
     * DERBY-6237(PreparedStatement.execute() fails starting 10.2 when 
     *  multiple rows are updated and 
     *  PreparedStatement.setCharacterStream(int, Reader, int) is used)  
	 * Test setCharacterStream on VARCHAR column 
     */
	public void testUpdateSetCharacterStreamVarchar() throws Exception
    {
		helperTestClobOrVarchar(false);
    }
	
    /**
     * DERBY-6237(PreparedStatement.execute() fails starting 10.2 when 
     *  multiple rows are updated and 
     *  PreparedStatement.setCharacterStream(int, Reader, int) is used) 
     * In 10.1, setCharacterStream to update CLOB and varchar columns
     *  work even when update is going to update more than one row
     *  
     *  @param 	testCLOB - true means test setCharacterStream on CLOB
     *                   - false means test setCharacterStream on VARCHAR
     * @throws Exception
     */
	private void helperTestClobOrVarchar(
			boolean testCLOB) throws Exception
	{
        Statement s = createStatement();
        dropTable("TESTUPDATECHARSTREAM");
        s.executeUpdate("CREATE TABLE TestUpdateCharStream ("+
                "c1 VARCHAR(64) NOT NULL, " +
          	    "c2 INTEGER, " +
                "c3 CLOB, " +
          	    "c4 VARCHAR(32000))"); 
        s.executeUpdate("INSERT INTO TestUpdateCharStream (c1, c2) " +
                "VALUES ('AAAAA', 1)");
        s.executeUpdate("INSERT INTO TestUpdateCharStream (c1, c2) " +
                "VALUES ('EEEEE', 1)");
        
        //update only one row and use short data
        helperTestDerby6237(1,1, testCLOB);
        //update only one row and use large data
        helperTestDerby6237(1,2, testCLOB);
        //update two rows and use short data
        //Once DERBY-6237 is fixed, we should remove following if condition
        // Following if condition will skip the test for 2 row update when
        //  testing CLOB columns in both embedded and network server with 
        //  short data.
        if ((!testCLOB))
            helperTestDerby6237(2,1, testCLOB);
        //update two rows and use large data
        //Once DERBY-6237 is fixed, we should remove following if condition
        // Following if condition will skip the test for 2 row update when
        //  testing CLOB columns in both embedded and network server with 
        //  large data.
        if (!(testCLOB))
            helperTestDerby6237(2,2, testCLOB);

        dropTable("TESTUPDATECHARSTREAM");
        s.close();
    }

	//numberOfRowsToUpdate - value 1 or 2
	//testVariation - if 1 then update CLOB/VARCHAR with short data
	//                if 2 then update CLOB/VARCHAR with large data
    //testCLOB - true means test setCharacterStream on CLOB
    //         - false means test setCharacterStream on VARCHAR
	private void helperTestDerby6237(int numberOfRowsToUpdate, 
            int testVariation,
            boolean testCLOB) throws Exception
    {
        CharAlphabet a1 = CharAlphabet.singleChar('a');

        //Following will update one or 2 rows depending on the 1st param
        //Following will update CLOB column or VARCHAR column with short
        // or large data depending on param 2
        //Following will update CLOB column or VARCHAR column depending
        // on 3rd param
        PreparedStatement ps = prepareStatement(
                "UPDATE TestUpdateCharStream SET " +
                (testCLOB==true ? "c3" : "c4") + " = ?, " + 
                "c2 = c2 + 1 WHERE c1 IN (?, ?)");
        switch (testVariation) {
        case 1 :
        	//test short data
            ps.setCharacterStream(1,
                    new LoopingAlphabetReader(50, a1), 50);
            break;
        case 2 :
        	//test large data
        	if (testCLOB) {
        		//for CLOB column, use 50K data
                ps.setCharacterStream(1,
                        new LoopingAlphabetReader(50000, a1), 50000);
        	} else {
        		//for VARCHAR column, use 32K data
	            ps.setCharacterStream(1,
	                    new LoopingAlphabetReader(32000, a1), 32000);
        	}
            break;
        }

        //First value in IN clause is getting set to 'AAAAA'
        // Using setCharacterStream on VARCHAR to set the value
        ps.setCharacterStream(2, new CharArrayReader("AAAAA".toCharArray()), 5);
        
        if (numberOfRowsToUpdate == 1 ) {
            //Second value in IN clause is also getting set to 'AAAAA', which 
            // means prepared statement will update only one row
            ps.setObject(3, "AAAAA", Types.VARCHAR);
        } else {
            //Second value in IN clause is also getting set to 'EEEEE', which 
            // means prepared statement will update two rows
            ps.setObject(3, "EEEEE", Types.VARCHAR);
        }        	
        ps.execute();
        
        //verify updated data. Update happened to either CLOB column or VARCHAR
        // column. It is decided by param 3
        ResultSet rs;
        ps = prepareStatement(
                "select " +
                (testCLOB==true ? "c3 " : "c4 ") + 
                "from TestUpdateCharStream " + 
                "WHERE c1 IN (?, ?)");
        ps.setCharacterStream(1, new CharArrayReader("AAAAA".toCharArray()), 5);
        if (numberOfRowsToUpdate == 1 ) {
            ps.setObject(2, "AAAAA", Types.VARCHAR);
        } else {
            ps.setObject(2, "EEEEE", Types.VARCHAR);
        }
    	rs = ps.executeQuery();
    	char[] c;
    	if (testVariation == 1){
        	//we are here to test short data 
            c = new char[50];
    	} else {
        	//we are here to test large data 
    		if (testCLOB)
    			c = new char[50000];
    		else
                c = new char[32000];
    	}
        Arrays.fill(c, 'a'); 
    	for (int i=0;i<numberOfRowsToUpdate;i++) {
        	rs.next();
        	if (!compareClobReader2CharArray(c,rs.getCharacterStream(1))) {
    			System.out.println("FAIL: " + 
        	        (testCLOB ? "CLOB " : "VARCHAR ") + "data should have matched");
    			rs.close();
    			ps.close();
    			return;
        	}
    	}
    	rs.close();
        ps.close();

    }
}