|
26 | 26 | import java.io.Reader; |
27 | 27 | import java.io.StringReader; |
28 | 28 | import java.io.Writer; |
| 29 | +import java.math.BigDecimal; |
29 | 30 | import java.sql.Blob; |
30 | 31 | import java.sql.Clob; |
31 | 32 | import java.sql.Connection; |
@@ -228,6 +229,60 @@ public static void setVarchar(PreparedStatement preparedStatement, int parameter |
228 | 229 | } |
229 | 230 | } |
230 | 231 |
|
| 232 | + /** |
| 233 | + * Set a CHAR datatype to a prepared statement with the value of the passed |
| 234 | + * in String, or the correct SQL null type if null |
| 235 | + * |
| 236 | + * @param preparedStatement The prepared statement |
| 237 | + * @param parameterIndex the index of the parameter |
| 238 | + * @param value the value to be set |
| 239 | + * |
| 240 | + * @throws SQLException if something went horribly wrong |
| 241 | + */ |
| 242 | + public static void setChar(PreparedStatement preparedStatement, int parameterIndex, String value) throws SQLException { |
| 243 | + if(null == value) { |
| 244 | + preparedStatement.setNull(parameterIndex, Types.CHAR); |
| 245 | + } else { |
| 246 | + preparedStatement.setString(parameterIndex, value); |
| 247 | + } |
| 248 | + } |
| 249 | + |
| 250 | + /** |
| 251 | + * Set a BINARY datatype to a prepared statement with the value of the passed |
| 252 | + * in String, or the correct SQL null type if null |
| 253 | + * |
| 254 | + * @param preparedStatement The prepared statement |
| 255 | + * @param parameterIndex the index of the parameter |
| 256 | + * @param value the value to be set |
| 257 | + * |
| 258 | + * @throws SQLException if something went horribly wrong |
| 259 | + */ |
| 260 | + public static void setBinary(PreparedStatement preparedStatement, int parameterIndex, String value) throws SQLException { |
| 261 | + if(null == value) { |
| 262 | + preparedStatement.setNull(parameterIndex, Types.BINARY); |
| 263 | + } else { |
| 264 | + preparedStatement.setString(parameterIndex, value); |
| 265 | + } |
| 266 | + } |
| 267 | + |
| 268 | + /** |
| 269 | + * Set a VARBINARY datatype to a prepared statement with the value of the passed |
| 270 | + * in String, or the correct SQL null type if null |
| 271 | + * |
| 272 | + * @param preparedStatement The prepared statement |
| 273 | + * @param parameterIndex the index of the parameter |
| 274 | + * @param value the value to be set |
| 275 | + * |
| 276 | + * @throws SQLException if something went horribly wrong |
| 277 | + */ |
| 278 | + public static void setVarbinary(PreparedStatement preparedStatement, int parameterIndex, String value) throws SQLException { |
| 279 | + if(null == value) { |
| 280 | + preparedStatement.setNull(parameterIndex, Types.VARBINARY); |
| 281 | + } else { |
| 282 | + preparedStatement.setString(parameterIndex, value); |
| 283 | + } |
| 284 | + } |
| 285 | + |
231 | 286 | /** |
232 | 287 | * Set a VARCHAR datatype to a prepared statement with the value of the passed |
233 | 288 | * in String, or the correct SQL null type if null |
@@ -264,6 +319,24 @@ public static void setInt(PreparedStatement preparedStatement, int parameterInde |
264 | 319 | } |
265 | 320 | } |
266 | 321 |
|
| 322 | + /** |
| 323 | + * Set a MEDIUMINT datatype to a prepared statement with the value of the passed |
| 324 | + * in Integer, or the correct SQL null type if null |
| 325 | + * |
| 326 | + * @param preparedStatement The prepared statement |
| 327 | + * @param parameterIndex the index of the parameter |
| 328 | + * @param value the value to be set |
| 329 | + * |
| 330 | + * @throws SQLException if something went horribly wrong |
| 331 | + */ |
| 332 | + public static void setMediumint(PreparedStatement preparedStatement, int parameterIndex, Integer value) throws SQLException { |
| 333 | + if(null == value) { |
| 334 | + preparedStatement.setNull(parameterIndex, Types.INTEGER); |
| 335 | + } else { |
| 336 | + preparedStatement.setInt(parameterIndex, value); |
| 337 | + } |
| 338 | + } |
| 339 | + |
267 | 340 | /** |
268 | 341 | * Set a INTEGER datatype to a prepared statement with the value of the passed |
269 | 342 | * in Integer, or the correct SQL null type if null |
@@ -296,6 +369,24 @@ public static void setSmallint(PreparedStatement preparedStatement, int paramete |
296 | 369 | } |
297 | 370 | } |
298 | 371 |
|
| 372 | + /** |
| 373 | + * Set a YEAR datatype to a prepared statement with the value of the passed |
| 374 | + * in Integer, or the correct SQL null type if null |
| 375 | + * |
| 376 | + * @param preparedStatement The prepared statement |
| 377 | + * @param parameterIndex the index of the parameter |
| 378 | + * @param value the value to be set |
| 379 | + * |
| 380 | + * @throws SQLException if something went horribly wrong |
| 381 | + */ |
| 382 | + public static void setYear(PreparedStatement preparedStatement, int parameterIndex, Integer value) throws SQLException { |
| 383 | + if(null == value) { |
| 384 | + preparedStatement.setNull(parameterIndex, Types.INTEGER); |
| 385 | + } else { |
| 386 | + preparedStatement.setInt(parameterIndex, value); |
| 387 | + } |
| 388 | + } |
| 389 | + |
299 | 390 | /** |
300 | 391 | * Set a SMALLSERIAL datatype to a prepared statement with the value of the passed |
301 | 392 | * in Integer, or the correct SQL null type if null |
@@ -406,6 +497,42 @@ public static void setMediumtext(PreparedStatement preparedStatement, int parame |
406 | 497 | setVarchar(preparedStatement, parameterIndex, value); |
407 | 498 | } |
408 | 499 |
|
| 500 | + /** |
| 501 | + * Set a TEXT datatype to a prepared statement with the value of the |
| 502 | + * passed in mediumtext, or the correct SQL null type if null |
| 503 | + * |
| 504 | + * @param preparedStatement The prepared statement |
| 505 | + * @param parameterIndex the index of the parameter |
| 506 | + * @param value the value to be set |
| 507 | + * |
| 508 | + * @throws SQLException if something went horribly wrong |
| 509 | + */ |
| 510 | + public static void setText(PreparedStatement preparedStatement, int parameterIndex, String value) throws SQLException { |
| 511 | + if(null == value) { |
| 512 | + preparedStatement.setNull(parameterIndex, Types.LONGVARCHAR); |
| 513 | + } else { |
| 514 | + preparedStatement.setString(parameterIndex, value); |
| 515 | + } |
| 516 | + } |
| 517 | + |
| 518 | + /** |
| 519 | + * Set a TINYTEXT datatype to a prepared statement with the value of the |
| 520 | + * passed in string, or the correct SQL null type if null |
| 521 | + * |
| 522 | + * @param preparedStatement The prepared statement |
| 523 | + * @param parameterIndex the index of the parameter |
| 524 | + * @param value the value to be set |
| 525 | + * |
| 526 | + * @throws SQLException if something went horribly wrong |
| 527 | + */ |
| 528 | + public static void setTinytext(PreparedStatement preparedStatement, int parameterIndex, String value) throws SQLException { |
| 529 | + if(null == value) { |
| 530 | + preparedStatement.setNull(parameterIndex, Types.VARCHAR); |
| 531 | + } else { |
| 532 | + preparedStatement.setString(parameterIndex, value); |
| 533 | + } |
| 534 | + } |
| 535 | + |
409 | 536 | /** |
410 | 537 | * Set a LONGTEXT datatype to a prepared statement with the value of the |
411 | 538 | * passed in longtext, or the correct SQL null type if null |
@@ -440,16 +567,16 @@ public static void setFloat(PreparedStatement preparedStatement, int parameterIn |
440 | 567 |
|
441 | 568 | /** |
442 | 569 | * Set a NUMERIC datatype to a prepared statement with the value of the passed |
443 | | - * in float, or the correct SQL null type if null |
| 570 | + * in BigDecimal, or the correct SQL null type if null |
444 | 571 | * |
445 | 572 | * @param preparedStatement The prepared statement |
446 | 573 | * @param parameterIndex the index of the parameter |
447 | 574 | * @param value the value to be set |
448 | 575 | * |
449 | 576 | * @throws SQLException if something went horribly wrong |
450 | 577 | */ |
451 | | - public static void setNumeric(PreparedStatement preparedStatement, int parameterIndex, Float value) throws SQLException { |
452 | | - setFloat(preparedStatement, parameterIndex, value); |
| 578 | + public static void setNumeric(PreparedStatement preparedStatement, int parameterIndex, BigDecimal value) throws SQLException { |
| 579 | + setDecimal(preparedStatement, parameterIndex, value); |
453 | 580 | } |
454 | 581 |
|
455 | 582 | /** |
@@ -482,11 +609,22 @@ public static void setTinyint(PreparedStatement preparedStatement, int parameter |
482 | 609 | * @throws SQLException if something went horribly wrong |
483 | 610 | */ |
484 | 611 | public static void setBoolean(PreparedStatement preparedStatement, int parameterIndex, Boolean value) throws SQLException { |
485 | | - if(null == value) { |
486 | | - preparedStatement.setNull(parameterIndex, Types.TINYINT); |
487 | | - } else { |
488 | | - preparedStatement.setBoolean(parameterIndex, value); |
489 | | - } |
| 612 | + setTinyint(preparedStatement, parameterIndex, value); |
| 613 | + } |
| 614 | + |
| 615 | + /** |
| 616 | + * Set a BOOL (or in sthis case conversion to a TINYINT) datatype to a |
| 617 | + * prepared statement with the value of the passed in boolean, or the correct |
| 618 | + * SQL null type if null |
| 619 | + * |
| 620 | + * @param preparedStatement The prepared statement |
| 621 | + * @param parameterIndex the index of the parameter |
| 622 | + * @param value the value to be set |
| 623 | + * |
| 624 | + * @throws SQLException if something went horribly wrong |
| 625 | + */ |
| 626 | + public static void setBool(PreparedStatement preparedStatement, int parameterIndex, Boolean value) throws SQLException { |
| 627 | + setTinyint(preparedStatement, parameterIndex, value); |
490 | 628 | } |
491 | 629 |
|
492 | 630 | /** |
@@ -517,14 +655,28 @@ public static void setDouble(PreparedStatement preparedStatement, int parameterI |
517 | 655 | * |
518 | 656 | * @throws SQLException if something went horribly wrong |
519 | 657 | */ |
520 | | - public static void setDecimal(PreparedStatement preparedStatement, int parameterIndex, Double value) throws SQLException { |
| 658 | + public static void setDecimal(PreparedStatement preparedStatement, int parameterIndex, BigDecimal value) throws SQLException { |
521 | 659 | if(null == value) { |
522 | 660 | preparedStatement.setNull(parameterIndex, Types.DECIMAL); |
523 | 661 | } else { |
524 | | - preparedStatement.setDouble(parameterIndex, value); |
| 662 | + preparedStatement.setBigDecimal(parameterIndex, value); |
525 | 663 | } |
526 | 664 | } |
527 | 665 |
|
| 666 | + /** |
| 667 | + * Set a DEC datatype to a prepared statement with the value of the passed |
| 668 | + * in double, or the correct SQL null type if null |
| 669 | + * |
| 670 | + * @param preparedStatement The prepared statement |
| 671 | + * @param parameterIndex the index of the parameter |
| 672 | + * @param value the value to be set |
| 673 | + * |
| 674 | + * @throws SQLException if something went horribly wrong |
| 675 | + */ |
| 676 | + public static void setDec(PreparedStatement preparedStatement, int parameterIndex, BigDecimal value) throws SQLException { |
| 677 | + setDecimal(preparedStatement, parameterIndex, value); |
| 678 | + } |
| 679 | + |
528 | 680 | /** |
529 | 681 | * Set a REAL datatype to a prepared statement with the value of the passed |
530 | 682 | * in double, or the correct SQL null type if null |
@@ -790,6 +942,10 @@ public static Short getNullableResultShort(ResultSet resultSet, int index) throw |
790 | 942 | return((Short)returnPossibleNullObject(resultSet, resultSet.getShort(index))); |
791 | 943 | } |
792 | 944 |
|
| 945 | + public static BigDecimal getNullableResultBigDecimal(ResultSet resultSet, int index) throws SQLException { |
| 946 | + return((BigDecimal)returnPossibleNullObject(resultSet, resultSet.getBigDecimal(index))); |
| 947 | + } |
| 948 | + |
793 | 949 |
|
794 | 950 | /** |
795 | 951 | * Get the underlying combo pooled result set |
|
0 commit comments