File: outparams.java

package info (click to toggle)
derby 10.14.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 79,056 kB
  • sloc: java: 691,961; sql: 42,686; xml: 20,512; sh: 3,373; sed: 96; makefile: 60
file content (1815 lines) | stat: -rw-r--r-- 45,927 bytes parent folder | download | duplicates (4)
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
/*

   Derby - Class org.apache.derbyTesting.functionTests.tests.lang.outparams

   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.lang;
import java.sql.*;

import org.apache.derby.tools.ij;
import java.io.PrintStream;
import java.math.BigInteger;
import java.math.BigDecimal;
import org.apache.derbyTesting.functionTests.util.BigDecimalHandler;

public class outparams
{
	
	private static boolean HAVE_BIG_DECIMAL;
	private static boolean HAVE_DRIVER_CLASS;
	private static String CLASS_NAME;
	
	//Get the class name to be used for the procedures
	//outparams - J2ME; outparams30 - non-J2ME
	static{
		if(BigDecimalHandler.representation != BigDecimalHandler.BIGDECIMAL_REPRESENTATION)
			HAVE_BIG_DECIMAL = false;
		else
			HAVE_BIG_DECIMAL = true;
		if(HAVE_BIG_DECIMAL)
			CLASS_NAME = "org.apache.derbyTesting.functionTests.tests.lang.outparams30.";
		else
			CLASS_NAME = "org.apache.derbyTesting.functionTests.tests.lang.outparams.";
	}
	
	static{
		try{
			Class.forName("java.sql.Driver");
			HAVE_DRIVER_CLASS = true;
		}
		catch(ClassNotFoundException e){
			//Used for JSR169
			HAVE_DRIVER_CLASS = false;
		}
	}
	
	static String[] outputMethods;
	//Get the array to be used based on HAVE_BIG_DECIMAL
	static{
		if(HAVE_BIG_DECIMAL){
			outputMethods = new String[] {
									"takesNothing",
							
									null, 
								
									null,
																	
									"takesShortPrimitive",
									null,
								
									"takesIntegerPrimitive",
									null,
								
									"takesLongPrimitive",
									null,
								
									"takesFloatPrimitive",
									null,
								
									"takesDoublePrimitive",
									null,
								
									"takesBigDecimal",
								
									"takesByteArray",
									
									"takesString",
									
									"takesDate",
									
									"takesTimestamp",
								
									"takesTime",
								
									null
								};
		}
		else{
			outputMethods = new String[] {
									"takesNothing",
							
									null, 
								
									null,
																	
									"takesShortPrimitive",
									null,
								
									"takesIntegerPrimitive",
									null,
								
									"takesLongPrimitive",
									null,
								
									"takesFloatPrimitive",
									null,
								
									"takesDoublePrimitive",
									null,
								
									null,
								
									"takesByteArray",
									
									"takesString",
									
									"takesDate",
									
									"takesTimestamp",
								
									"takesTime",
								
									null
								};			
		}
	}

	// parameter types for outputMethods.
	private static final String[] outputProcParam =
	{
		null, // "takesNothing",

		null, 
	
		null,
			
		"SMALLINT", // "takesShortPrimitive",
		null,
	
		"INT", // "takesIntegerPrimitive",
		null,
	
		"BIGINT", // "takesLongPrimitive",
		null,
	
		"REAL", // "takesFloatPrimitive",
		null,
	
		"DOUBLE", // "takesDoublePrimitive",
		null,
	
		"DECIMAL(10,4)", // "takesBigDecimal",
	
		"VARCHAR(40) FOR BIT DATA", // "takesByteArray",
		
		"VARCHAR(40)", // "takesString",
		
		"DATE", // "takesDate",
		
		"TIMESTAMP", // "takesTimestamp",
	
		"TIME", // "takesTime",
	
		null
	};
		
	static String returnMethods[];
	//Get the array to be used based on HAVE_BIG_DECIMAL
	static{
		if(HAVE_BIG_DECIMAL){
			returnMethods = new String[] 	{
									"returnsNothing",
				
									null,
									null,
								
									"returnsShortP",
									null,
								
									"returnsIntegerP",
									null,
								
									"returnsLongP",
									null,
								
									"returnsFloatP",
									null,
								
									"returnsDoubleP",
									null,
								
									"returnsBigDecimal",
								
									"returnsByteArray",
									
									"returnsString",
									
									"returnsDate",
									
									"returnsTimestamp",
								
									"returnsTime",
								
									null
								};
		}
		else{
			returnMethods = new String[] 	{
									"returnsNothing",
				
									null,
									null,
								
									"returnsShortP",
									null,
								
									"returnsIntegerP",
									null,
								
									"returnsLongP",
									null,
								
									"returnsFloatP",
									null,
								
									"returnsDoubleP",
									null,
								
									null,
								
									"returnsByteArray",
									
									"returnsString",
									
									"returnsDate",
									
									"returnsTimestamp",
								
									"returnsTime",
								
									null
								};
		}
	}
	
	static String[] returnMethodType =
	{
		null, // "returnsNothing",

		null, // "returnsBytePrimitive",
		null, // "returnsByte",
	
		"SMALLINT", // "returnsShortPrimitive",
		null, // "returnsShort",
	
		"INT", // "returnsIntegerPrimitive",
		null, // "returnsInteger",
	
		"BIGINT", // "returnsLongPrimitive",
		null, // "returnsLong",
	
		"REAL", // "returnsFloatPrimitive",
		null, // "returnsFloat",
	
		"DOUBLE", // "returnsDoublePrimitive",
		null, // "returnsDouble",
	
		"DECIMAL(10,2)", // "returnsBigDecimal",
	
		"VARCHAR(40) FOR BIT DATA", // "returnsByteArray",
		
		"VARCHAR(40)", // "returnsString",
		
		"DATE", // "returnsDate",
		
		"TIMESTAMP", // "returnsTimestamp",
	
		"TIME", // "returnsTime",
	
		null, // "returnsBigInteger"
	};
	
	//JDBC type (java.sql.Types) corresponding to the methods
	static int[] paramJDBCType =
	{
		Types.NULL, // "returnsNothing",

		Types.NULL, // "returnsBytePrimitive",
		Types.NULL, // "returnsByte",
	
		Types.SMALLINT, // "returnsShortPrimitive",
		Types.NULL, // "returnsShort",
	
		Types.INTEGER, // "returnsIntegerPrimitive",
		Types.NULL, // "returnsInteger",
	
		Types.BIGINT, // "returnsLongPrimitive",
		Types.NULL, // "returnsLong",
	
		Types.REAL, // "returnsFloatPrimitive",
		Types.NULL, // "returnsFloat",
	
		Types.DOUBLE, // "returnsDoublePrimitive",
		Types.NULL, // "returnsDouble",
	
		Types.NUMERIC, // "returnsBigDecimal",
	
		Types.VARBINARY, // "returnsByteArray",
		
		Types.VARCHAR, // "returnsString",
		
		Types.DATE, // "returnsDate",
		
		Types.TIMESTAMP, // "returnsTimestamp",
	
		Types.TIME, // "returnsTime",
	
		Types.NULL, // "returnsBigInteger"
	};	
	
	static final int types[] =
	{
		Types.BIT,
		Types.BOOLEAN,
		Types.TINYINT,
		Types.SMALLINT,
		Types.INTEGER,
		Types.BIGINT,
		Types.FLOAT,
		Types.REAL,
		Types.DOUBLE,
		Types.NUMERIC,
		Types.DECIMAL,
		Types.CHAR,
		Types.VARCHAR,
		Types.LONGVARCHAR,
		Types.DATE,
		Types.TIME, 
		Types.TIMESTAMP,
		Types.BINARY,
		Types.VARBINARY,
		Types.LONGVARBINARY,
		Types.OTHER
	};
	
	static final String typeNames[] =
	{
		"BIT",
		"BOOLEAN",
		"TINYINT",
		"SMALLINT",
		"INTEGER",
		"BIGINT",
		"FLOAT",
		"REAL",
		"DOUBLE",
		"NUMERIC",
		"DECIMAL",
		"CHAR",
		"VARCHAR",
		"LONGVARCHAR",
		"DATE",
		"TIME",
		"TIMESTAMP",
		"BINARY",
		"VARBINARY",
		"LONGVARBINARY",
		"OTHER"
	};

	//public static Connection conn;

	public static void main (String[] argv) throws Throwable
	{
   		ij.getPropertyArg(argv); 
        Connection conn = ij.startJBMS();

        runTests( conn);
    }

    public static void runTests( Connection conn) throws Throwable
    {        
		conn.setAutoCommit(false);	

		testMisc(conn);
		testNull(conn);
		testUpdate(conn);
		testEachOutputType(conn);
		testReturnTypes(conn);
		testOtherOutputType(conn);
		testManyOut(conn);
		//Uses a procedure with nested connection - Cannot be tested with JSR169
		if(HAVE_DRIVER_CLASS)
			test5116(conn);
	}

	private static void testMisc(Connection conn) throws Throwable
	{
		System.out.println("==============================================");
		System.out.println("TESTING BOUNDARY CONDITIONS");
		System.out.println("==============================================\n");

		Statement scp = conn.createStatement();

		scp.execute("CREATE PROCEDURE takesString(OUT P1 VARCHAR(40), IN P2 INT) " +
						"EXTERNAL NAME '" + CLASS_NAME + "takesString'" +
						" NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");

		CallableStatement cs = conn.prepareCall("call takesString(?,?)");

		// register a normal int as an output param, should fail
		boolean failed = false;
		try
		{
			cs.registerOutParameter(2, Types.INTEGER);
		}
		catch (SQLException se)
		{
			failed = true;
			System.out.println("Expected exception "+se);
		}
		if (!failed)
		{
			System.out.println("registerOutParameter on non-output didn't fail");
		}

		// invalid param number
		failed = false;
		try
		{
			cs.registerOutParameter(9, Types.INTEGER);
		}
		catch (SQLException se)
		{
			failed = true;
			System.out.println("Expected exception "+se);
		}
		if (!failed)
		{
			System.out.println("registerOutParameter on bad value didn't fail");
		}

		// invalid param number
		failed = false;
		try
		{
			cs.registerOutParameter(0, Types.INTEGER);
		}
		catch (SQLException se)
		{
			failed = true;
			System.out.println("Expected exception "+se);
		}
		if (!failed)
		{
			System.out.println("registerOutParameter on bad value didn't fail");
		}

		// set before register, bad type, should fail as is output parameter.	
		try
		{
			cs.setDouble(1, 1);
			System.out.println("FAIL setDouble() on takesString() accepted");
		}
		catch (SQLException se)
		{
			System.out.println("Expected exception "+se);
		}

		// set before register, should fail as is output parameter.
		try
		{
			cs.setString(1, "hello");
			System.out.println("FAIL setString() on takesString() accepted");
		}
		catch (SQLException se)
		{
			System.out.println("Expected exception "+se);
		}

		cs.registerOutParameter(1, Types.CHAR);
		cs.setInt(2, Types.INTEGER);
		try
		{
			cs.execute();
		}
		catch (SQLException se)
		{
			System.out.println("cs.execute() got unexpected exception: "+se);
		}

		// shouldn't have to reregister the type, and shouldn't
		// need to set the output parameters
		cs.clearParameters();
		cs.setInt(2, Types.INTEGER);
		try
		{
			cs.execute();
		}
		catch (SQLException se)
		{
			System.out.println("cs.execute() got unexpected exception: "+se);
		}
		cs.close();
		scp.execute("DROP PROCEDURE takesString");

		scp.execute("CREATE FUNCTION returnsString(P2 INT) RETURNS VARCHAR(40) " +
						"EXTERNAL NAME '" + CLASS_NAME + "returnsString'" +
						" NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
		// return output params -- cannot do set on return output param
		cs = conn.prepareCall("? = call returnsString(?)");
		try
		{
			cs.setString(1, new String("test"));
			System.out.println("ERROR: setString() on return output parameter succeeded");
		}
		catch (SQLException se)
		{
			System.out.println("Expected exception on setString() on a return output param: "+se);
		}
		cs.close();
		scp.execute("DROP FUNCTION returnsString");

		// lets try ? = call syntax on a call that doesn't return anything
		
		scp.execute("CREATE PROCEDURE returnsNothing() " +
						"EXTERNAL NAME '" + CLASS_NAME + "returnsNothing'" +
						" NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
		try
		{
			cs = conn.prepareCall("? = call returnsNothing()");
			System.out.println("ERROR: no exception on prepare of '? = call returnsNothing()");
		}
		catch (SQLException se)
		{
			System.out.println("Expected exception on prepare of '? = call returnsNothing()': "+se);
		}
		scp.execute("DROP PROCEDURE returnsNothing");
	}

	
	private static void testNull(Connection conn) throws Throwable
	{
		System.out.println("==============================================");
		System.out.println("TESTING NULLS");
		System.out.println("==============================================\n");
		System.out.println("Test for bug 4317, passing null value for a parameter");

		Statement scp = conn.createStatement();

		scp.execute("CREATE PROCEDURE testNullBug4317(IN P1 VARCHAR(10)) " +
						"EXTERNAL NAME '" + CLASS_NAME + "testNullBug4317'" +
						" NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");


		CallableStatement cs0 = conn.prepareCall("call testNullBug4317(?)");
		try
		{
			cs0.setString(1, null);		// passing in null
			cs0.execute();
		}
		catch (SQLException se)
		{
			System.out.println("cs0.execute() got unexpected exception: "+se);
		}

		try
		{
			// BUG 5928 - setNull throws an exception - fixed.
			cs0.setNull(1, java.sql.Types.VARCHAR);		// passing in null
			cs0.execute();
		}
		catch (SQLException se)
		{
			System.out.println("cs0.execute() got unexpected exception: "+se);
		}
		cs0.close();
		scp.execute("DROP PROCEDURE testNullBug4317");


	}

	// test: do we get an appropriate update count when using ?=call?
	private static void testUpdate(Connection conn) throws Throwable
	{
		System.out.println("==============================================");
		System.out.println("TESTING UPDATE COUNT");
		System.out.println("==============================================\n");

		Statement scp = conn.createStatement();

		scp.execute("CREATE FUNCTION returnsIntegerP(P1 INT) RETURNS INTEGER " +
						"EXTERNAL NAME '" + CLASS_NAME + "returnsIntegerP'" +
						" NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");



		CallableStatement cs = conn.prepareCall("? = call returnsIntegerP(0)");
		cs.registerOutParameter(1, Types.INTEGER);
		try
		{
			int updCount = cs.executeUpdate();
			System.out.println("executeUpdate on ? = call returnsIntegerP returned "+updCount);
			System.out.println("getString(1) returned "+cs.getString(1));
		}
		catch (SQLException se)
		{
			System.out.println("cs.execute() got unexpected exception: "+se);
		}

		cs.close();
		scp.execute("DROP FUNCTION returnsIntegerP");
		scp.close();
	}

	// should do get setString() to use a string that is appropriate for
	//	the target type
	private static void testEachOutputType(Connection conn) throws Throwable
	{
		System.out.println("==============================================");
		System.out.println("TESTING NORMAL OUTPUT PARAMETERS");
		System.out.println("==============================================\n");
		CallableStatement cs = null;

		for (int doSetObject = 0; doSetObject < 3; doSetObject++)
		{
			switch (doSetObject)
			{
				case 0:
					System.out.println("...starting doing setXXX for each type xxx");
					break;
				case 1:
					System.out.println("...now doing setObject on each type xxx");
					break;
				case 2:
					System.out.println("...not doing any setXXX, just OUT parameters, not IN/OUT");
					break;
			}

			for (int method = 0; method < outputMethods.length; method++)
			{
				String methodName = outputMethods[method];
				if (methodName == null)
					continue;

				System.out.println("\n------------------------------------");

				Statement scp = conn.createStatement();
				String str;
				if (methodName.indexOf("Nothing") == -1)
				{

					scp.execute("CREATE PROCEDURE " + methodName + "(INOUT P1 " + outputProcParam[method] + ", IN P2 INT) " +
						"EXTERNAL NAME '" + CLASS_NAME + "" + methodName +
						"' NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");


					if (method%2 == 0)
						str = "{call "+methodName+"(?,?)}";
					else
						str = "call "+methodName+"(?,?)";
				}
				else
				{
					scp.execute("CREATE PROCEDURE " + methodName + "() " +
						"EXTERNAL NAME '" + CLASS_NAME + "" + methodName +
						"' NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
					str = "{call "+methodName+"()}";
				}


	
				System.out.println(str);
				try 
				{
					cs = conn.prepareCall(str);
				}
				catch (SQLException se)
				{
					System.out.println("ERROR: unexpected exception "+se);
					throw se;
				}
	
				for (int type = 0; type < types.length; type++)
				{
					cs.clearParameters();
					System.out.println();
					try
					{
						System.out.println("\n\tcs.registerOutParameter(1, "+typeNames[type]+")");
						cs.registerOutParameter(1, types[type]);
					} 
					catch (SQLException se)
					{
						System.out.println("\tException "+se);
						continue;
					}
	
					StringBuffer buf = new StringBuffer();
					try
					{
						if (doSetObject == 0) 
						{
							callSetMethod(cs, 1, types[type], buf);
						}
						else if (doSetObject == 1)
						{
							callSetObject(cs, 1, types[type], buf);
						}
						else
						{
							// only try this once
							type = types.length-1;
							buf.append("...no setXXX(1) at all");
						}
					}
					catch (SQLException se)
					{
						System.out.println("\t"+buf.toString());
						System.out.println("\tException "+se);
						continue;
					}
					System.out.println("\t"+buf.toString());
					cs.setInt(2, types[type]);
	
					try
					{
						System.out.println("\tcs.execute()");
						boolean hasResultSet = cs.execute();
						if (hasResultSet)
							System.out.println("testEachOutputType HAS RESULT SET cs.execute() returned true");
						}
					catch (SQLException se)
					{
						System.out.println("\tException "+se);
						continue;
					}
					for (int getType = 0; getType < types.length; getType++)
					{
						StringBuffer getbuf = new StringBuffer();
						try
						{
							callGetMethod(cs, 1, types[getType], paramJDBCType[method], getbuf);
						}
						catch (SQLException se)
						{
							getbuf.append(se);
						}
						System.out.println("\t\t\t"+getbuf.toString());
					}
	
				}

				cs.close();

				scp.execute("DROP PROCEDURE " + methodName);
				scp.close();
			}
		}

		System.out.println("------------------------------------\n");

	}

	// test that everything works ok when we regsiter the param as type OTHER.
	// should be able to get/setXXX of the appropriate type
	private static void testOtherOutputType(Connection conn) throws Throwable
	{
		System.out.println("==============================================");
		System.out.println("TESTING OUTPUT PARAMETERS WITH register(OTHER)");
		System.out.println("==============================================\n");
		CallableStatement cs = null;

		for (int method = 0; method < outputMethods.length; method++)
		{
			String methodName = outputMethods[method];
			if (methodName == null)
				continue;
			System.out.println("\n------------------------------------");


			Statement scp = conn.createStatement();
			String str;
			if (methodName.indexOf("Nothing") == -1)
			{

				scp.execute("CREATE PROCEDURE " + methodName + "(INOUT P1 " + outputProcParam[method] + ", IN P2 INT) " +
					"EXTERNAL NAME '" + CLASS_NAME + "" + methodName +
					"' NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");


				if (method%2 == 0)
					str = "{call "+methodName+"(?,?)}";
				else
					str = "call "+methodName+"(?,?)";
			}
			else
			{
				scp.execute("CREATE PROCEDURE " + methodName + "() " +
					"EXTERNAL NAME '" + CLASS_NAME + "" + methodName +
					"' NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
				str = "{call "+methodName+"()}";
			}

			System.out.println(str);
			try 
			{
				cs = conn.prepareCall(str);
			}
			catch (SQLException se)
			{
				System.out.println("ERROR: unexpected exception "+se);
				throw se;
			}
	
			for (int type = 0; type < types.length; type++)
			{
				cs.clearParameters();
				System.out.println();
				try
				{
					System.out.println("\n\tcs.registerOutParameter(1, Types.OTHER)");
					cs.registerOutParameter(1, Types.OTHER);
				} 
				catch (SQLException se)
				{
					System.out.println("\tException "+se);
					continue;
				}

				StringBuffer buf = new StringBuffer();
				try
				{
					callSetMethod(cs, 1, types[type], buf);
				}
				catch (SQLException se)
				{
					System.out.println("\t"+buf.toString());
					System.out.println("\tException "+se);
					continue;
				}
				System.out.println("\t"+buf.toString());
				cs.setInt(2, types[type]);

				try
				{
					System.out.println("\tcs.execute()");
					cs.execute();
				}
				catch (SQLException se)
				{
					System.out.println("\tException "+se);
					continue;
				}
				for (int getType = 0; getType < types.length; getType++)
				{
					StringBuffer getbuf = new StringBuffer();
					try
					{
						callGetMethod(cs, 1, types[getType], Types.OTHER , getbuf);
					}
					catch (SQLException se)
					{
						getbuf.append(se);
					}
					System.out.println("\t\t\t"+getbuf.toString());
				}

			}

			cs.close();

			scp.execute("DROP PROCEDURE " + methodName);
			scp.close();
		}

		System.out.println("------------------------------------\n");
	}

	private static void testReturnTypes(Connection conn) throws Throwable
	{
		System.out.println("==============================================\n");
		System.out.println("TESTING RETURN OUTPUT PARAMETERS");
		System.out.println("==============================================\n");
		CallableStatement cs = null;
		for (int method = 0; method < returnMethods.length; method++)
		{
			String methodName = returnMethods[method];
			if (methodName == null)
				continue;

			Statement scf = conn.createStatement();
			String str;
			String dropRoutine;
			if (methodName.indexOf("Nothing") != -1)
			{

				scf.execute("CREATE PROCEDURE " + methodName + "()" +
					" EXTERNAL NAME '" + CLASS_NAME + "" + methodName +
					"' NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");


				dropRoutine = "DROP PROCEDURE " + methodName;

				str = "{call "+returnMethods[method]+"()}";
			}
			else
			{

				scf.execute("CREATE FUNCTION " + methodName + "(P1 INT) RETURNS " + returnMethodType[method] +
					" EXTERNAL NAME '" + CLASS_NAME + "" + methodName +
					"' NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");
				dropRoutine = "DROP FUNCTION " + methodName;

				str = "{? = call "+returnMethods[method]+"(?)}";
			}


				
			System.out.println("\n------------------------------------");
				

			System.out.println(str);
			try 
			{
				cs = conn.prepareCall(str);
			}
			catch (SQLException se)
			{
				System.out.println("ERROR: unexpected exception "+se);
				throw se;
			}

			for (int type = 0; type < types.length; type++)
			{
				cs.clearParameters();
				System.out.println();
				try
				{
					System.out.println("\n\tcs.registerOutParameter(1, "+typeNames[type]+")");
					cs.registerOutParameter(1, types[type]);
				} 
				catch (SQLException se)
				{
					System.out.println("\tException "+se);
					continue;
				}
				try
				{
					cs.setInt(2, types[type]);
				}
				catch (SQLException se)
				{
					System.out.println("\tUnexpected exception on cs.setInt(2, "+types[type]+"): "+se);
					continue;
				}

				try
				{
					System.out.println("\tcs.execute()");
					boolean hasResultSet = cs.execute();
					if (hasResultSet)
						System.out.println("testReturnTypes HAS RESULT SET cs.execute() returned true");

				}
				catch (SQLException se)
				{
					System.out.println("\tException "+se);
					continue;
				}
				for (int getType = 0; getType < types.length; getType++)
				{
					StringBuffer getbuf = new StringBuffer();
					try
					{
						callGetMethod(cs, 1, types[getType], paramJDBCType[method], getbuf);
					}
					catch (SQLException se)
					{
						getbuf.append(se);
					}
					System.out.println("\t\t\t"+getbuf.toString());
				}

			}

			cs.close();
			scf.execute(dropRoutine);
			scf.close();
		}

		System.out.println("------------------------------------\n");

	}

	private static void callSetObject(CallableStatement cs, int arg, int type, StringBuffer strbuf) throws Throwable
	{

		switch (type)	
		{
			case Types.BIT:
			case Types.BOOLEAN:
				strbuf.append("setObject("+arg+", true)");
				cs.setObject(arg, true);
				break;

			case Types.TINYINT:
				strbuf.append("setObject("+arg+", 6)");
				cs.setObject(arg, 6);
				break;

			case Types.SMALLINT:
				strbuf.append("setObject("+arg+", 66)");
				cs.setObject(arg, 66);
				break;

			case Types.INTEGER:
				strbuf.append("setObject("+arg+", 666)");
				cs.setObject(arg, 666);
				break;

			case Types.BIGINT:
				strbuf.append("setObject("+arg+", 666)");
				cs.setObject(arg, 666L);
				break;

			case Types.FLOAT:
			case Types.REAL:
				strbuf.append("setObject("+arg+", 666)");
				cs.setObject(arg, 666f);
				break;

			case Types.DOUBLE:
				strbuf.append("setObject("+arg+", 666)");
				cs.setObject(arg, 666.0);
				break;

			case Types.DECIMAL:
			case Types.NUMERIC:
				strbuf.append("setObject("+arg+", 666.666)");
				BigDecimalHandler.setObjectString(cs,arg,"666.666");
				break;

			case Types.CHAR:
			case Types.VARCHAR:
			case Types.LONGVARCHAR:
				strbuf.append("setObject("+arg+", \"Set via setString()\")");
				cs.setObject(arg, "Set via setString()");
				break;

			case Types.BINARY:
			case Types.VARBINARY:
			case Types.LONGVARBINARY:
				strbuf.append("setObject("+arg+", byte[])");
				byte[] myarray = new byte[16];
				myarray[0] = (byte)255;
				cs.setObject(arg, myarray);
				break;

			case Types.DATE:
				strbuf.append("setObject("+arg+", Date.valueOf(1999-09-09))");
				cs.setObject(arg, Date.valueOf("1999-09-09"));
				break;

			case Types.TIME:
				strbuf.append("setObject("+arg+", Time.valueOf(09:09:09))");
				cs.setObject(arg, Time.valueOf("09:09:09"));
				break;

			case Types.TIMESTAMP:
				strbuf.append("setObject("+arg+", Timestamp.valueOf(1999-09-09 09:09:09.999))");
				cs.setObject(arg, Timestamp.valueOf("1999-09-09 09:09:09.999"));
				break;

			case Types.OTHER:
				strbuf.append("setObject("+arg+", new BigInteger(666))");
				cs.setObject(arg, new BigInteger("666"));
				break;

			default:
				throw new Throwable("TEST ERROR: unexpected type "+type);
		}	
	}
	private static void callSetMethod(CallableStatement cs, int arg, int type, StringBuffer strbuf) throws Throwable
	{
		switch (type)	
		{
			case Types.BIT:
			case Types.BOOLEAN:
				strbuf.append("setBoolean("+arg+", true)");
				cs.setBoolean(arg, true);
				break;

			case Types.TINYINT:
				strbuf.append("setByte("+arg+", 6)");
				cs.setByte(arg, (byte)6);
				break;

			case Types.SMALLINT:
				strbuf.append("setShort("+arg+", 66)");
				cs.setShort(arg, (short)66);
				break;

			case Types.INTEGER:
				strbuf.append("setInt("+arg+", 666)");
				cs.setInt(arg, 666);
				break;

			case Types.BIGINT:
				strbuf.append("setLong("+arg+", 666)");
				cs.setLong(arg, 666);
				break;

			case Types.FLOAT:
			case Types.REAL:
				strbuf.append("setFLoat("+arg+", 666)");
				cs.setFloat(arg, 666);
				break;

			case Types.DOUBLE:
				strbuf.append("setDouble("+arg+", 666)");
				cs.setDouble(arg, 666);
				break;

			case Types.DECIMAL:
			case Types.NUMERIC:
				strbuf.append("setBigDecimal("+arg+", 666.666)");
				BigDecimalHandler.setBigDecimalString(cs,arg,"666.666");
				break;

			case Types.CHAR:
			case Types.VARCHAR:
			case Types.LONGVARCHAR:
				strbuf.append("setString("+arg+", \"Set via setString()\")");
				cs.setString(arg, "Set via setString()");
				break;

			case Types.BINARY:
			case Types.VARBINARY:
			case Types.LONGVARBINARY:
				strbuf.append("setBytes("+arg+", byte[])");
				byte[] myarray = new byte[16];
				myarray[0] = (byte)255;
				cs.setBytes(arg, myarray);
				break;

			case Types.DATE:
				strbuf.append("setDate("+arg+", Date.valueOf(1999-09-09))");
				cs.setDate(arg, Date.valueOf("1999-09-09"));
				break;

			case Types.TIME:
				strbuf.append("setTime("+arg+", Time.valueOf(09:09:09))");
				cs.setTime(arg, Time.valueOf("09:09:09"));
				break;

			case Types.TIMESTAMP:
				strbuf.append("setTimestamp("+arg+", Timestamp.valueOf(1999-09-09 09:09:09.999))");
				cs.setTimestamp(arg, Timestamp.valueOf("1999-09-09 09:09:09.999"));
				break;

			case Types.OTHER:
				strbuf.append("setObject("+arg+", new BigInteger(666))");
				cs.setObject(arg, new BigInteger("666"));
				break;

			default:
				throw new Throwable("TEST ERROR: unexpected type "+type);
		}	
	}

	private static void callGetMethod(CallableStatement cs, int arg, int type, int paramType ,StringBuffer strbuf) throws Throwable
	{
		switch (type)	
		{
			case Types.BIT:
			case Types.BOOLEAN:
				strbuf.append("getBoolean("+arg+") = ");
				strbuf.append(cs.getBoolean(arg));
				break;

			case Types.TINYINT:
				strbuf.append("getByte("+arg+") = ");
				strbuf.append(Byte.toString(cs.getByte(arg)));
				break;

			case Types.SMALLINT:
				strbuf.append("getShort("+arg+") = ");
				strbuf.append(Short.toString(cs.getShort(arg)));
				break;

			case Types.INTEGER:
				strbuf.append("getInt("+arg+") = ");
				strbuf.append(Integer.toString(cs.getInt(arg)));
				break;

			case Types.BIGINT:
				strbuf.append("getLong("+arg+") = ");
				strbuf.append(Long.toString(cs.getLong(arg)));
				break;

			case Types.FLOAT:
			case Types.REAL:
				strbuf.append("getFloat("+arg+") = ");
				strbuf.append(Float.toString(cs.getFloat(arg)));
				break;

			case Types.DOUBLE:
				strbuf.append("getDouble("+arg+") = ");
				strbuf.append(Double.toString(cs.getDouble(arg)));
				break;

			case Types.DECIMAL:
			case Types.NUMERIC:
				strbuf.append("getBigDecimal("+arg+") = ");
				strbuf.append(BigDecimalHandler.getBigDecimalString(cs,arg,paramType));
				break;

			case Types.CHAR:
			case Types.VARCHAR:
			case Types.LONGVARCHAR:
				strbuf.append("getString("+arg+") = ");
				String s = cs.getString(arg);
				if (s.startsWith("[B@"))
					s = "byte[] reference";
				strbuf.append(s);
				break;

			case Types.BINARY:
			case Types.VARBINARY:
			case Types.LONGVARBINARY:
				strbuf.append("getBytes("+arg+") = ");
				byteArrayToString(cs.getBytes(arg), strbuf);
				break;

			case Types.DATE:
				strbuf.append("getDate("+arg+") = ");
				Date date = cs.getDate(arg);
				strbuf.append(date == null ? "null" : date.toString());
				break;

			case Types.TIME:
				strbuf.append("getTime("+arg+") = ");
				Time time = cs.getTime(arg);
				strbuf.append(time == null ? "null" : time.toString());
				break;

			case Types.TIMESTAMP:
				strbuf.append("getTimestamp("+arg+") = ");
				Timestamp timestamp = cs.getTimestamp(arg);
				strbuf.append(timestamp == null ? "null" : timestamp.toString());
				break;

			case Types.OTHER:
				strbuf.append("getObject("+arg+") = ");
				Object o = cs.getObject(arg);
				if (o == null)
				{
					strbuf.append("null");
				}
				else if (o instanceof byte[])
				{
					byteArrayToString((byte[])o, strbuf);
				}
				else
				{
					strbuf.append(o.toString());
				}

				break;

			default:
				throw new Throwable("TEST ERROR: unexpected type "+type);
		}	
	}

	static private void byteArrayToString(byte[] barray, StringBuffer strbuf)
	{
		if (barray == null)
		{
			strbuf.append("null");
		}
		else
		{
			for (int i = 0; i<barray.length; i++)
			{
				strbuf.append(barray[i]);
			}
		}
	}

	private static String getStringOfType(int type) throws Throwable
	{
		switch (type)
		{
			case Types.CHAR:
			case Types.VARCHAR:
			case Types.LONGVARCHAR:
				return "I am a string";

			case Types.TINYINT:
			case Types.SMALLINT:
			case Types.INTEGER:
			case Types.BIGINT:
			case Types.OTHER:		// other is bigInt
				return "3";

			case Types.FLOAT:
			case Types.REAL:
			case Types.DECIMAL:
			case Types.NUMERIC:
				return  "3.33";

			case Types.DATE:		
				return "1933-03-03";

			case Types.TIME:		
				return "03:03:03";

			case Types.TIMESTAMP:		
				return "1933-03-03 03:03:03.333";

			case Types.BINARY:		
			case Types.VARBINARY:		
			case Types.LONGVARBINARY:
				return "00680065006c006c006f";

			case Types.BIT:
			case Types.BOOLEAN:
				return "true";

			default:
				throw new Throwable("bad type "+type);
		}	
	}

	/////////////////////////////////////////////////////////////
	//	
	// OUTPUT PARAMETER METHODS
	//
	/////////////////////////////////////////////////////////////
	public static void testNull(Boolean passedInNull, Boolean setToNull, Integer[] retval) throws Throwable
	{
		if (passedInNull.booleanValue())
		{
			if (retval[0] != null)
			{
				throw new Throwable("testNull() got a non-null param when it should have been null");
			}
		}

		retval[0] = (setToNull.booleanValue()) ? null : 66;
	}

	public static void testNullBug4317(String passedInNull) throws Throwable
	{
	}

	public static void takesNothing()
	{
	}
	public static void takesBytePrimitive(byte[] outparam, int type)
	{
		outparam[0]+=outparam[0];
	}
	public static void takesByte(Byte[] outparam, int type)
	{
		outparam[0] = ((byte)(outparam[0] == null ? 33 : outparam[0].byteValue()*2));
	}

	public static void takesShortPrimitive(short[] outparam, int type)
	{
		outparam[0]+=outparam[0];
	}
	public static void takesShort(Short[] outparam, int type)
	{
      outparam[0] = (short) ((byte)(outparam[0] == null ? 33 : outparam[0].shortValue()*2));
	}

	public static void takesIntegerPrimitive(int[] outparam, int type)
	{
		outparam[0]+=outparam[0];
	}
	public static void takesInteger(Integer[] outparam, int type)
	{
		outparam[0] = outparam[0] == null ? 33 : outparam[0].intValue()*2;
	}

	public static void takesLongPrimitive(long[] outparam, int type)
	{
		outparam[0]+=outparam[0];
	}
	public static void takesLong(Long[] outparam, int type)
	{
      outparam[0] = (long)(outparam[0] == null ? 33 : outparam[0].longValue()*2);
	}

	public static void takesDoublePrimitive(double[] outparam, int type)
	{
		outparam[0]+=outparam[0];
	}
	public static void takesDouble(Double[] outparam, int type)
	{
      outparam[0] = (double) (outparam[0] == null ? 33 : outparam[0].doubleValue()*2);
	}

	public static void takesFloatPrimitive(float[] outparam, int type)
	{
		outparam[0]+=outparam[0];
	}
	public static void takesFloat(Float[] outparam, int type)
	{
      outparam[0] = (float) (outparam[0] == null ? 33 : outparam[0].floatValue()*2);
	}

	public static void takesBooleanPrimitive(boolean[] outparam, int type)
	{
		outparam[0] = true;
	}
	public static void takesBoolean(Boolean[] outparam, int type)
	{
		outparam[0] = true;
	}

	public static void takesByteArray(byte[][] outparam, int type)
	{
		byte[] myarray = new byte[16];
		myarray[0] = (byte)255;
		outparam[0] = myarray;
	}

	public static void takesDate(Date[] outparam, int type)
	{
		outparam[0] = Date.valueOf("1966-06-06");
	}

	public static void takesTime(Time[] outparam, int type)
	{
		outparam[0] = Time.valueOf("06:06:06");
	}

	public static void takesTimestamp(Timestamp[] outparam, int type)
	{
		outparam[0] = Timestamp.valueOf("1966-06-06 06:06:06.666");
	}

	public static void takesString(String[] outparam, int type) throws Throwable
	{
		outparam[0] = getStringOfType(type);
	}

	public static void takesBigInteger(BigInteger[] outparam, int type)
	{
		outparam[0] = (outparam[0] == null ? new BigInteger("33") : outparam[0].add(outparam[0]));
	}
	
	
	/////////////////////////////////////////////////////////////
	//	
	// RETURN PARAMETER METHODS
	//
	/////////////////////////////////////////////////////////////
	public static void returnsNothing()
	{
	}

	public static byte returnsByteP(int type)
	{
		return 66;
	}
	public static Byte returnsByte(int type)
	{
		return (byte)66;
	}

	public static short returnsShortP(int type)
	{
		return 666;
	}
	public static Short returnsShort(int type)
	{
		return (short)666;
	}

	public static int returnsIntegerP(int type)
	{
		return 666;
	}
	public static Integer returnsInteger(int type)
	{
		return 666;
	}

	public static long returnsLongP(int type)
	{
		return 666;
	}
	public static Long returnsLong(int type)
	{
		return 666L;
	}

	public static float returnsFloatP(int type)
	{
		return 666;
	}
	public static Float returnsFloat(int type)
	{
		return 666f;
	}

	public static double returnsDoubleP(int type)
	{
		return 666;
	}
	public static Double returnsDouble(int type)
	{
		return 666.0;
	}

	public static byte[] returnsByteArray(int type)
	{
		byte[] myarray = new byte[16];
		myarray[0] = (byte)255;
		return myarray;
	}

	public static String returnsString(int type) throws Throwable
	{
		return getStringOfType(type);
	}

	public static Date returnsDate(int type)
	{
		return Date.valueOf("1966-06-06");
	}

	public static Time returnsTime(int type)
	{
		return Time.valueOf("06:06:06");
	}

	public static Timestamp returnsTimestamp(int type)
	{
		return Timestamp.valueOf("1966-06-06 06:06:06.666");
	}

	public static BigInteger returnsBigInteger(int type)
	{
		return new BigInteger("666");
	}


	// these come from the performance test JDBC.Parameters that was failing
	private static void testManyOut(Connection conn) throws SQLException {

		System.out.println("start testManyOut");

		Statement scp = conn.createStatement();

		scp.execute("CREATE PROCEDURE OP_OUT " +
			"(OUT I1 INT, OUT I2 INT, OUT I3 INT, OUT I4 INT, OUT I5 INT, "+
			"OUT V1 VARCHAR(40), OUT V2 VARCHAR(40), OUT V3 VARCHAR(40), OUT V4 VARCHAR(40), OUT V5 VARCHAR(40)) "+

			"EXTERNAL NAME '" + CLASS_NAME + "output' NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");


		scp.execute("CREATE PROCEDURE OP_INOUT " +
			"(INOUT I1 INT, INOUT I2 INT, INOUT I3 INT, INOUT I4 INT, INOUT I5 INT, " +
			"INOUT V1 VARCHAR(40), INOUT V2 VARCHAR(40), INOUT V3 VARCHAR(40), INOUT V4 VARCHAR(40), INOUT V5 VARCHAR(40)) " +

			"EXTERNAL NAME '" + CLASS_NAME + "output' NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA");


		CallableStatement csOut_cs = conn.prepareCall("CALL OP_OUT(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
		CallableStatement csInOut_cs = conn.prepareCall("CALL OP_INOUT(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");

		System.out.println("Ten OUT parameters");

		executeOutput(csOut_cs);
		executeOutput(csOut_cs);

		csOut_cs.close();

		System.out.println("Ten INOUT parameters");


		setupInput(csInOut_cs);
		executeOutput(csInOut_cs);

		setupInput(csInOut_cs);
		executeOutput(csInOut_cs);

		csInOut_cs.close();

		scp.execute("DROP PROCEDURE OP_OUT");
		scp.execute("DROP PROCEDURE OP_INOUT");
		scp.close();


		System.out.println("end testManyOut");


	}


	private static void setupInput(PreparedStatement ps) throws SQLException {

		ps.setInt(1, 0);
		ps.setInt(2, 0);
		ps.setInt(3, 99);
		ps.setInt(4, 103);
		ps.setInt(5, 1456);

		ps.setNull(6, Types.CHAR);
		ps.setString(7, null);
		ps.setString(8, "hello");
		ps.setString(9, "goodbye");
		ps.setString(10, "welcome");
	}
	private static void executeOutput(CallableStatement cs) throws SQLException {

		for (int p = 1; p <= 5; p++)
			cs.registerOutParameter(p, Types.INTEGER);

		for (int p = 6; p <= 10; p++)
			cs.registerOutParameter(p, Types.VARCHAR);

		cs.execute();

		for (int p = 1; p <= 5; p++) {
			System.out.println("  " + p + " = " + cs.getInt(p) + " was null " + cs.wasNull());
	
		}
		for (int p = 6; p <= 10; p++) {
			System.out.println("  " + p + " = " + cs.getString(p) + " was null " + cs.wasNull());
		}
	}


	public static void output(int[] a1, int[] a2, int[] a3, int[] a4, int[] a5,
		String[] s1, String[] s2, String[] s3, String[] s4, String[] s5) {

		System.out.println("  a1 = " + a1[0]);
		System.out.println("  a2 = " + a2[0]);
		System.out.println("  a3 = " + a3[0]);
		System.out.println("  a4 = " + a4[0]);
		System.out.println("  a5 = " + a5[0]);

		System.out.println("  s1 = " + s1[0]);
		System.out.println("  s2 = " + s2[0]);
		System.out.println("  s3 = " + s3[0]);
		System.out.println("  s4 = " + s4[0]);
		System.out.println("  s5 = " + s5[0]);

		a1[0] = 0;
		a2[0] = 0;
		a3[0] = 77;
		a4[0] = 4;
		a5[0] = 2003;

		s1[0] = null;
		s2[0] = null;
		s3[0] = "cloudscape";
		s4[0] = "jbms";
		s5[0] = "IBM CS";
	}

	private static void test5116(Connection conn) throws Throwable
	{
		System.out.println("==============================================");
		System.out.println("TESTING FIX OF 5116 -- VAR BIT VARYING INPUT");
		System.out.println("==============================================\n");

		Statement stmt = conn.createStatement();
		stmt.executeUpdate("CREATE TABLE ACTIVITY_INSTANCE_T (" +
    "AIID                               char(16) for bit data              NOT NULL ," +
    "KIND                               INTEGER                            NOT NULL ," +
    "PIID                               char(16) for bit data              NOT NULL ," +
    "PTID                               char(16) for bit data              NOT NULL ," +
    "ATID                               char(16) for bit data              NOT NULL ," +
    "RUN_MODE                           INTEGER                            NOT NULL ," +
    "FINISHED                           TIMESTAMP                                   ," +
    "ACTIVATED                          TIMESTAMP                                   ," +
    "STARTED                            TIMESTAMP                                   ," +
    "LAST_MODIFIED                      TIMESTAMP                                   ," +
    "LAST_STATE_CHANGE                  TIMESTAMP                                   ," +
    "STATE                              INTEGER                            NOT NULL ," +
    "TRANS_COND_VALUES                  VARCHAR(66) FOR BIT DATA           NOT NULL ," +
    "NUM_CONN_ACT_EVA                   INTEGER                            NOT NULL ," +
    "NUMBER_OF_ITERATIONS               INTEGER                            NOT NULL ," +
    "NUMBER_OF_RETRIES                  INTEGER                            NOT NULL ," +
    "HAS_CUSTOM_ATTRIBUTES              SMALLINT                           NOT NULL ," +
    "NON_BLOCK_PTID                     char(16) for bit data              NOT NULL ," +
    "NON_BLOCK_PIID                     char(16) for bit data              NOT NULL ," +
    "EXPIRES                            TIMESTAMP                                   ," +
    "TASK_ID                            VARCHAR(254)                                ," +
    "UNHANDLED_EXCEPTION                BLOB(3993600)                       ," +
    "SUB_PROCESS_PIID                   char(16) for bit data                                    ," +
    "OWNER                              VARCHAR(32)                                 ," +
    "USER_INPUT                         VARCHAR(130) FOR BIT DATA                   ," +
    "DESCRIPTION                        VARCHAR(254)                                ," +
    "VERSION_ID                         SMALLINT                           NOT NULL ," +
    "PRIMARY KEY ( AIID ) )");

		stmt.execute("CREATE PROCEDURE doInsertion(IN P1 VARCHAR(2) FOR BIT DATA) " +
						"EXTERNAL NAME '" + CLASS_NAME + "doInsertion'" +
						" MODIFIES SQL DATA LANGUAGE JAVA PARAMETER STYLE JAVA");

		CallableStatement cs = conn.prepareCall("call doInsertion (?)");
		cs.setNull(1, java.sql.Types.VARBINARY);
		cs.execute();
        byte [] b = new byte[2];
        b[0]=1; b[1] = 2;
        cs.setBytes( 1, b );
		cs.execute();
		cs.close();
		stmt.executeUpdate("DROP PROCEDURE doInsertion");
		stmt.close();
	}

	public static void doInsertion (byte[] p25) throws Throwable
	{
		Connection connNested = DriverManager.getConnection("jdbc:default:connection");
		Statement stmt = connNested.createStatement();
		stmt.executeUpdate("delete from ACTIVITY_INSTANCE_T");

        String strStmt = "INSERT INTO ACTIVITY_INSTANCE_T VALUES( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? )";
        PreparedStatement pstmt = connNested.prepareStatement( strStmt );

        byte [] b = new byte[2];
        b[0]=1;
		byte[] b2 = new byte[1];
		b2[0] = 0;

         pstmt.setBytes( 1, b ); //ids
         pstmt.setInt( 2, 0);
         pstmt.setBytes( 3, b );
         pstmt.setBytes( 4, b );
         pstmt.setBytes( 5, b );
         pstmt.setInt( 6, 0);
         pstmt.setNull( 7, java.sql.Types.TIMESTAMP);
         pstmt.setNull( 8, java.sql.Types.TIMESTAMP);
         pstmt.setNull( 9, java.sql.Types.TIMESTAMP);
         pstmt.setNull( 10, java.sql.Types.TIMESTAMP);
         pstmt.setNull( 11, java.sql.Types.TIMESTAMP);
         pstmt.setInt( 12, 0);
         pstmt.setBytes( 13, b );

         pstmt.setInt( 14, 0);
         pstmt.setInt( 15, 0);
         pstmt.setInt( 16, 0);
         pstmt.setBoolean( 17, false);
         pstmt.setBytes( 18, b );
         pstmt.setBytes( 19, b );
         pstmt.setNull( 20, java.sql.Types.TIMESTAMP);
         pstmt.setNull( 21, java.sql.Types.VARCHAR);
         pstmt.setNull( 22, java.sql.Types.BLOB );
         pstmt.setNull( 23, java.sql.Types.VARBINARY );
         pstmt.setNull( 24, java.sql.Types.VARCHAR);
		if (p25 == null)
             pstmt.setNull( 25, java.sql.Types.VARBINARY);
		else
			 pstmt.setBytes(25, p25);
         pstmt.setNull( 26, java.sql.Types.VARCHAR);
         pstmt.setShort( 27, (short) 0);
         pstmt.executeUpdate();
         pstmt.close();

         pstmt = connNested.prepareStatement( "SELECT version_id, user_input FROM activity_instance_t");
         ResultSet resultSet = pstmt.executeQuery();
         System.out.println("Executed query");
         while( resultSet.next() )
         {
            System.out.println("i= " + resultSet.getInt(1) );
            byte [] userInput = resultSet.getBytes(2);
            if( userInput == null || resultSet.wasNull() )
            {
				if( userInput == null)
               		System.out.println("UserInput = null");
				if (resultSet.wasNull())
               		System.out.println("resultSet wasNull");
            }
            else
            {
               System.out.println("UserInput length  = " + userInput.length + " bytes");
               for( int i=0; i<userInput.length; i++ )
               {
                  System.out.println( i + ") = " + userInput[i] );
               }
            }
         }
         System.out.println("Close result set.");
         resultSet.close();
         pstmt.close();
         stmt.close();
		 connNested.close();
   }
}