private static String castToString(final Object in) throws SQLException { try { if (in instanceof String) { return (String) in; } if (in instanceof Clob) { return asString((Clob) in); } // convert any unknown objects to string. return in.toString(); } catch (final Exception e) { throw cannotCastException(in.getClass().getName(), "String", e); } }
private static long castToLong(final Object in) throws SQLException { try { if (in instanceof String) { return Long.parseLong((String) in); } if (in instanceof Number) { return ((Number) in).longValue(); } if (in instanceof java.util.Date) { return ((java.util.Date) in).getTime(); } if (in instanceof Boolean) { return (Boolean) in ? 1L : 0L; } if (in instanceof Clob) { return Long.parseLong(asString((Clob) in)); } if (in instanceof Character) { return Long.parseLong(in.toString()); } } catch (final Exception e) { throw cannotCastException(in.getClass().getName(), "long", e); } throw cannotCastException(in.getClass().getName(), "long"); }
private static float castToFloat(final Object in) throws SQLException { try { if (in instanceof String) { return Float.parseFloat((String) in); } if (in instanceof Number) { return ((Number) in).floatValue(); } if (in instanceof java.util.Date) { return ((java.util.Date) in).getTime(); } if (in instanceof Boolean) { return (Boolean) in ? 1f : 0f; } if (in instanceof Clob) { return Float.parseFloat(asString((Clob) in)); } if (in instanceof Character) { return Float.parseFloat(in.toString()); } } catch (final Exception e) { throw cannotCastException(in.getClass().getName(), "float", e); } throw cannotCastException(in.getClass().getName(), "float"); }
private static int castToInt(final Object in) throws SQLException { try { if (in instanceof String) { return Integer.parseInt((String) in); } if (in instanceof Number) { return ((Number) in).intValue(); } if (in instanceof java.util.Date) { return (int) ((java.util.Date) in).getTime(); } if (in instanceof Boolean) { return (Boolean) in ? 1 : 0; } if (in instanceof Clob) { return Integer.parseInt(asString((Clob) in)); } if (in instanceof Character) { return Integer.parseInt(in.toString()); } } catch (final Exception e) { throw cannotCastException(in.getClass().getName(), "int", e); } throw cannotCastException(in.getClass().getName(), "int"); }
private static short castToShort(final Object in) throws SQLException { try { if (in instanceof String) { return Short.parseShort((String) in); } if (in instanceof Number) { return ((Number) in).shortValue(); } if (in instanceof java.util.Date) { return (short) ((java.util.Date) in).getTime(); } if (in instanceof Boolean) { return (Boolean) in ? (short) 1 : (short) 0; } if (in instanceof Clob) { return Short.parseShort(asString((Clob) in)); } if (in instanceof Character) { return Short.parseShort(in.toString()); } } catch (final Exception e) { throw cannotCastException(in.getClass().getName(), "short", e); } throw cannotCastException(in.getClass().getName(), "short"); }
private static double castToDouble(final Object in) throws SQLException { try { if (in instanceof String) { return Double.parseDouble((String) in); } if (in instanceof Number) { return ((Number) in).doubleValue(); } if (in instanceof java.util.Date) { return ((java.util.Date) in).getTime(); } if (in instanceof Boolean) { return (Boolean) in ? 1d : 0d; } if (in instanceof Clob) { return Double.parseDouble(asString((Clob) in)); } if (in instanceof Character) { return Double.parseDouble(in.toString()); } } catch (final Exception e) { throw cannotCastException(in.getClass().getName(), "double", e); } throw cannotCastException(in.getClass().getName(), "double"); }
rc = (Boolean) in ? BigDecimal.ONE : BigDecimal.ZERO; } else if (in instanceof Clob) { rc = new BigDecimal(asString((Clob) in)); } else if (in instanceof Character) { rc = new BigDecimal(new char[]{(Character) in});