List of usage examples for java.lang Byte Byte
@Deprecated(since = "9") public Byte(String s) throws NumberFormatException
From source file:com.github.xbn.array.helper.NewPrimitiveArrayHelper.java
public Byte getWrapper(Object obj_thatIsPrimArr, int index, String array_name) { try {/*from w w w .j a v a2 s . c om*/ return (new Byte(getPrimitiveArray(obj_thatIsPrimArr, NullContainer.BAD, array_name)[index])); } catch (RuntimeException rx) { ciObjNullUnexpectedTypeOrBadIndex(obj_thatIsPrimArr, index, array_name); throw rx; } }
From source file:org.jdesigner.platform.web.converter.NumberConverter.java
/** * Default String to Number conversion.//www . ja va2 s. c om * <p> * This method handles conversion from a String to the following types: * <ul> * <li><code>java.lang.Byte</code></li> * <li><code>java.lang.Short</code></li> * <li><code>java.lang.Integer</code></li> * <li><code>java.lang.Long</code></li> * <li><code>java.lang.Float</code></li> * <li><code>java.lang.Double</code></li> * <li><code>java.math.BigDecimal</code></li> * <li><code>java.math.BigInteger</code></li> * </ul> * * @param sourceType * The type being converted from * @param targetType * The Number type to convert to * @param value * The String value to convert. * * @return The converted Number value. */ private Number toNumber(Class sourceType, Class targetType, String value) { // Number Grouping if (DataUtils.isNumberGrouping()) { value = NumberUtils.removeNumberGrouping(value); } // int if (targetType.equals(int.class)) { return new Integer(value); } // float if (targetType.equals(float.class)) { return new Float(value); } // long if (targetType.equals(long.class)) { return new Long(value); } // double if (targetType.equals(double.class)) { return new Double(value); } // Byte if (targetType.equals(Byte.class)) { return new Byte(value); } // Short if (targetType.equals(Short.class)) { return new Short(value); } // Integer if (targetType.equals(Integer.class)) { return new Integer(value); } // Long if (targetType.equals(Long.class)) { return new Long(value); } // Float if (targetType.equals(Float.class)) { return new Float(value); } // Double if (targetType.equals(Double.class)) { return new Double(value); } // BigDecimal if (targetType.equals(BigDecimal.class)) { return new BigDecimal(value); } // BigInteger if (targetType.equals(BigInteger.class)) { return new BigInteger(value); } String msg = toString(getClass()) + " cannot handle conversion from '" + toString(sourceType) + "' to '" + toString(targetType) + "'"; if (log().isWarnEnabled()) { log().warn(" " + msg); } throw new ConversionException(msg); }
From source file:es.caib.zkib.jxpath.util.BasicTypeConverter.java
/** * Allocate a number of a given type and value. * @param type destination class// w ww.j a v a 2s . c om * @param value double * @return Number */ protected Number allocateNumber(Class type, double value) { type = TypeUtils.wrapPrimitive(type); if (type == Byte.class) { return new Byte((byte) value); } if (type == Short.class) { return new Short((short) value); } if (type == Integer.class) { return new Integer((int) value); } if (type == Long.class) { return new Long((long) value); } if (type == Float.class) { return new Float((float) value); } if (type == Double.class) { return new Double(value); } if (type == BigInteger.class) { return BigInteger.valueOf((long) value); } if (type == BigDecimal.class) { return new BigDecimal(value); } String classname = type.getName(); Class initialValueType = null; if ("java.util.concurrent.atomic.AtomicInteger".equals(classname)) { initialValueType = int.class; } if ("java.util.concurrent.atomic.AtomicLong".equals(classname)) { initialValueType = long.class; } if (initialValueType != null) { try { return (Number) type.getConstructor(new Class[] { initialValueType }) .newInstance(new Object[] { allocateNumber(initialValueType, value) }); } catch (Exception e) { throw new JXPathTypeConversionException(classname, e); } } return null; }
From source file:com.espertech.esper.regression.expr.TestCaseExpr.java
public void testCaseSyntax2StringsNBranches() { // Test of the various coercion user cases. String caseExpr = "select case intPrimitive" + " when 1 then Boolean.toString(boolPrimitive) " + " when 2 then Boolean.toString(boolBoxed) " + " when 3 then Integer.toString(intPrimitive) " + " when 4 then Integer.toString(intBoxed)" + " when 5 then Long.toString(longPrimitive) " + " when 6 then Long.toString(longBoxed) " + " when 7 then Character.toString(charPrimitive) " + " when 8 then Character.toString(charBoxed) " + " when 9 then Short.toString(shortPrimitive) " + " when 10 then Short.toString(shortBoxed) " + " when 11 then Byte.toString(bytePrimitive) " + " when 12 then Byte.toString(byteBoxed) " + " when 13 then Float.toString(floatPrimitive) " + " when 14 then Float.toString(floatBoxed) " + " when 15 then Double.toString(doublePrimitive) " + " when 16 then Double.toString(doubleBoxed) " + " when 17 then theString " + " else 'x' end as p1 " + " from " + SupportBean.class.getName() + ".win:length(1)"; EPStatement selectTestCase = epService.getEPAdministrator().createEPL(caseExpr); selectTestCase.addListener(testListener); assertEquals(String.class, selectTestCase.getEventType().getPropertyType("p1")); sendSupportBeanEvent(true, new Boolean(false), 1, new Integer(0), 0L, new Long(0L), '0', new Character('a'), (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0, new Double(0.0), null, SupportEnum.ENUM_VALUE_1); EventBean theEvent = testListener.getAndResetLastNewData()[0]; assertEquals("true", theEvent.get("p1")); sendSupportBeanEvent(true, new Boolean(false), 2, new Integer(0), 0L, new Long(0L), '0', new Character('a'), (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0, new Double(0.0), null, SupportEnum.ENUM_VALUE_1); theEvent = testListener.getAndResetLastNewData()[0]; assertEquals("false", theEvent.get("p1")); sendSupportBeanEvent(true, new Boolean(false), 3, new Integer(0), 0L, new Long(0L), '0', new Character('a'), (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0, new Double(0.0), null, SupportEnum.ENUM_VALUE_1); theEvent = testListener.getAndResetLastNewData()[0]; assertEquals("3", theEvent.get("p1")); sendSupportBeanEvent(true, new Boolean(false), 4, new Integer(4), 0L, new Long(0L), '0', new Character('a'), (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0, new Double(0.0), null, SupportEnum.ENUM_VALUE_1); theEvent = testListener.getAndResetLastNewData()[0]; assertEquals("4", theEvent.get("p1")); sendSupportBeanEvent(true, new Boolean(false), 5, new Integer(0), 5L, new Long(0L), '0', new Character('a'), (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0, new Double(0.0), null, SupportEnum.ENUM_VALUE_1); theEvent = testListener.getAndResetLastNewData()[0]; assertEquals("5", theEvent.get("p1")); sendSupportBeanEvent(true, new Boolean(false), 6, new Integer(0), 0L, new Long(6L), '0', new Character('a'), (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0, new Double(0.0), null, SupportEnum.ENUM_VALUE_1); theEvent = testListener.getAndResetLastNewData()[0]; assertEquals("6", theEvent.get("p1")); sendSupportBeanEvent(true, new Boolean(false), 7, new Integer(0), 0L, new Long(0L), 'A', new Character('a'), (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0, new Double(0.0), null, SupportEnum.ENUM_VALUE_1); theEvent = testListener.getAndResetLastNewData()[0]; assertEquals("A", theEvent.get("p1")); sendSupportBeanEvent(true, new Boolean(false), 8, new Integer(0), 0L, new Long(0L), 'A', new Character('a'), (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0, new Double(0.0), null, SupportEnum.ENUM_VALUE_1); theEvent = testListener.getAndResetLastNewData()[0]; assertEquals("a", theEvent.get("p1")); sendSupportBeanEvent(true, new Boolean(false), 9, new Integer(0), 0L, new Long(0L), 'A', new Character('a'), (short) 9, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0, new Double(0.0), null, SupportEnum.ENUM_VALUE_1); theEvent = testListener.getAndResetLastNewData()[0]; assertEquals("9", theEvent.get("p1")); sendSupportBeanEvent(true, new Boolean(false), 10, new Integer(0), 0L, new Long(0L), 'A', new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f, new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1); theEvent = testListener.getAndResetLastNewData()[0]; assertEquals("10", theEvent.get("p1")); sendSupportBeanEvent(true, new Boolean(false), 11, new Integer(0), 0L, new Long(0L), 'A', new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f, new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1); theEvent = testListener.getAndResetLastNewData()[0]; assertEquals("11", theEvent.get("p1")); sendSupportBeanEvent(true, new Boolean(false), 12, new Integer(0), 0L, new Long(0L), 'A', new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f, new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1); theEvent = testListener.getAndResetLastNewData()[0]; assertEquals("12", theEvent.get("p1")); sendSupportBeanEvent(true, new Boolean(false), 13, new Integer(0), 0L, new Long(0L), 'A', new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f, new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1); theEvent = testListener.getAndResetLastNewData()[0]; assertEquals("13.0", theEvent.get("p1")); sendSupportBeanEvent(true, new Boolean(false), 14, new Integer(0), 0L, new Long(0L), 'A', new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f, new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1); theEvent = testListener.getAndResetLastNewData()[0]; assertEquals("14.0", theEvent.get("p1")); sendSupportBeanEvent(true, new Boolean(false), 15, new Integer(0), 0L, new Long(0L), 'A', new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f, new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1); theEvent = testListener.getAndResetLastNewData()[0]; assertEquals("15.0", theEvent.get("p1")); sendSupportBeanEvent(true, new Boolean(false), 16, new Integer(0), 0L, new Long(0L), 'A', new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f, new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1); theEvent = testListener.getAndResetLastNewData()[0]; assertEquals("16.0", theEvent.get("p1")); sendSupportBeanEvent(true, new Boolean(false), 17, new Integer(0), 0L, new Long(0L), 'A', new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f, new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1); theEvent = testListener.getAndResetLastNewData()[0]; assertEquals("testCoercion", theEvent.get("p1")); sendSupportBeanEvent(true, new Boolean(false), -1, new Integer(0), 0L, new Long(0L), 'A', new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f, new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1); theEvent = testListener.getAndResetLastNewData()[0]; assertEquals("x", theEvent.get("p1")); }
From source file:com.hoho.android.usbserial.examples.SerialConsoleActivity.java
private void updateReceivedData(byte[] data) throws IOException, InterruptedException { int i = 0;// w w w . j a v a 2 s. co m int ct = 0; //varaible used in the serial data reading sendMessage(WEAR_MESSAGE_PATH, data); for (; i < data.length; i++) { int nn = new Byte(data[i]).intValue() & 0xFF; ; if (nn == 0) { zeroCount++; bufferFilled = 0; predict(); } else if (bufferFilled >= NUMBER_OF_INPUTS) { continue; } else { int k = ct / 3; if ((k & 2) == 0 && ct % 3 == 1) { bufferSerial[bufferFilled++] = nn; } ct++; } } }
From source file:com.turborep.turbotracker.banking.service.BankingServiceImpl.java
@Override public List<MoAccount> getBankAccountList(int theFrom, int theTo) throws BankingException { Session aSession = null;// w w w . ja va2 s. c o m List<MoAccount> aQueryList = null; String aCustomerQry = "SELECT * FROM moAccount "; /* LIMIT " + theFrom + ", " + theTo; */ MoAccount aMoaccount = null; boolean inActiveVal = false; try { aQueryList = new ArrayList<MoAccount>(); aSession = itsSessionFactory.openSession(); Query aQuery = aSession.createSQLQuery(aCustomerQry); Iterator<?> aIterator = aQuery.list().iterator(); while (aIterator.hasNext()) { aMoaccount = new MoAccount(); Object[] aObj = (Object[]) aIterator.next(); aMoaccount.setMoAccountId((Integer) aObj[0]); if (aObj[1] instanceof Boolean) { inActiveVal = (Boolean) aObj[1]; if (inActiveVal) aMoaccount.setInActive(new Byte("1")); else aMoaccount.setInActive(new Byte("0")); } else if (aObj[1] instanceof Byte) { aMoaccount.setInActive((Byte) aObj[1]); } aMoaccount.setAccountType((Short) aObj[2]); aMoaccount.setDescription((String) aObj[3]); aMoaccount.setCoAccountIDAsset((Integer) aObj[4]); aMoaccount.setCoAccountIDDeposits((Integer) aObj[5]); aMoaccount.setCoAccountIDInterest((Integer) aObj[6]); aMoaccount.setCoAccountIDFees((Integer) aObj[7]); aMoaccount.setOpenBalance((BigDecimal) aObj[8]); aMoaccount.setAdditions((BigDecimal) aObj[9]); aMoaccount.setSubtractions((BigDecimal) aObj[10]); aMoaccount.setUndepositedReceipts((BigDecimal) aObj[11]); aMoaccount.setUnprintedPayables((BigDecimal) aObj[12]); aMoaccount.setUnprintedPayroll((BigDecimal) aObj[13]); aMoaccount.setNextCheckNumber((Integer) aObj[14]); aMoaccount.setEndingBalance((BigDecimal) aObj[15]); aMoaccount.setCompany1((String) aObj[16]); aMoaccount.setCompany2((String) aObj[17]); aMoaccount.setCompany3((String) aObj[18]); aMoaccount.setCompany4((String) aObj[19]); aMoaccount.setCompany5((String) aObj[20]); aMoaccount.setBank1((String) aObj[21]); aMoaccount.setBank2((String) aObj[22]); aMoaccount.setBank3((String) aObj[23]); aMoaccount.setBank4((String) aObj[24]); aMoaccount.setBank5((String) aObj[25]); aMoaccount.setCheckCode((String) aObj[26]); aMoaccount.setRoutingNumber((String) aObj[27]); aMoaccount.setAccountNumber((String) aObj[28]); if (aObj[29] != null && (Boolean) aObj[29] == true) { aMoaccount.setLogoYN(true); } else { aMoaccount.setLogoYN(false); } if (aObj[30] != null) { aMoaccount.setLineNo(JobUtil.ConvertintoInteger(aObj[30].toString())); } else { aMoaccount.setLineNo(0); } aQueryList.add(aMoaccount); itsLogger.info("moaccount ID" + aMoaccount.getMoAccountId()); } } catch (Exception e) { itsLogger.error(e.getMessage(), e); BankingException aBankingException = new BankingException(e.getMessage(), e); throw aBankingException; } finally { aSession.flush(); aSession.close(); aCustomerQry = null; } return aQueryList; }
From source file:org.apache.openjpa.jdbc.schema.Column.java
/** * Return the default value set for this column, if any. If only a default * string has been set, attempts to convert it to the right type based * on the Java type set for this column. *///from www .j ava2 s. co m public Object getDefault() { if (_default != null) return _default; if (_defaultStr == null) return null; switch (_javaType) { case JavaTypes.BOOLEAN: case JavaTypes.BOOLEAN_OBJ: _default = ("true".equals(_defaultStr)) ? Boolean.TRUE : Boolean.FALSE; break; case JavaTypes.BYTE: case JavaTypes.BYTE_OBJ: _default = new Byte(_defaultStr); break; case JavaTypes.CHAR: case JavaTypes.CHAR_OBJ: _default = Character.valueOf(_defaultStr.charAt(0)); break; case JavaTypes.DOUBLE: case JavaTypes.DOUBLE_OBJ: _default = new Double(_defaultStr); break; case JavaTypes.FLOAT: case JavaTypes.FLOAT_OBJ: _default = new Float(_defaultStr); break; case JavaTypes.INT: case JavaTypes.INT_OBJ: _default = Integer.parseInt(_defaultStr); break; case JavaTypes.LONG: case JavaTypes.LONG_OBJ: _default = Long.parseLong(_defaultStr); break; case JavaTypes.NUMBER: case JavaTypes.BIGDECIMAL: _default = new BigDecimal(_defaultStr); break; case JavaTypes.SHORT: case JavaTypes.SHORT_OBJ: _default = new Short(_defaultStr); break; case JavaTypes.DATE: _default = new java.util.Date(_defaultStr); break; case JavaTypes.BIGINTEGER: _default = new BigInteger(_defaultStr); break; case JavaSQLTypes.SQL_DATE: _default = Date.valueOf(_defaultStr); break; case JavaSQLTypes.TIMESTAMP: _default = Timestamp.valueOf(_defaultStr); break; case JavaSQLTypes.TIME: _default = Time.valueOf(_defaultStr); break; default: _default = _defaultStr; } return _default; }
From source file:com.appglu.impl.CrudTemplateTest.java
@Test public void writeAllDataTypes() throws ParseException { mockServer.expect(requestTo("http://localhost/appglu/v1/tables/data_types")) .andExpect(method(HttpMethod.POST)).andExpect(header("Content-Type", jsonMediaType.toString())) .andExpect(content().string(compactedJson("data/crud_write_all_data_types"))) .andRespond(withStatus(HttpStatus.CREATED).body(compactedJson("data/crud_create_response")) .headers(responseHeaders)); Row row = new Row(); String string = new String("a very long string for test"); row.put("boolean", true); row.put("short", new Short((short) 1)); row.put("byte", new Byte((byte) 2)); row.put("byteArray", string.getBytes()); row.put("float", new Float(1.5f)); row.put("double", new Double(7.5d)); row.put("integer", new Integer(10)); row.put("long", new Long(21474836475L)); row.put("bigInteger", new BigInteger("9223372036854775807123")); row.put("string", string); Date datetime = DateUtils.parseDate("2010-01-15T12:10:00+0000"); row.putDatetime("datetime", datetime); Date time = DateUtils.parseDate("1970-01-01T12:10:00+0000"); row.putTime("time", time); Date date = DateUtils.parseDate("2010-01-15T00:00:00+0000"); row.putDate("date", date); Object id = crudOperations.create("data_types", row); Assert.assertEquals(8, id);// ww w.j av a 2s . co m mockServer.verify(); }
From source file:gedi.util.FileUtils.java
public static <T> T read(BinaryReader in) throws IOException, ClassNotFoundException { String clsName = in.getString(); if (clsName.length() == 1) { switch (clsName) { case "A": return (T) in.getString(); case "B": return (T) new Byte(in.get()); case "S": return (T) new Short(in.getShort()); case "I": return (T) new Integer(in.getInt()); case "L": return (T) new Long(in.getLong()); case "F": return (T) new Float(in.getFloat()); case "D": return (T) new Double(in.getDouble()); }//from ww w . j a va 2s . c om } Class<T> cls = (Class<T>) Class.forName(clsName); if (BinarySerializable.class.isAssignableFrom(cls)) { try { T re = cls.newInstance(); ((BinarySerializable) re).deserialize(in); return re; } catch (InstantiationException | IllegalAccessException e) { throw new IOException("Could not instantiate " + cls.getName(), e); } } else throw new RuntimeException("Only BinarySerializables can be deserialized right now!"); }
From source file:org.apache.cocoon.util.JDBCTypeConversions.java
/** * Set the Statement column so that the results are mapped correctly. * * @param statement the prepared statement * @param position the position of the column * @param value the value of the column//from w w w . j a v a 2 s . c om */ public static void setColumn(PreparedStatement statement, int position, Object value, Integer typeObject) throws Exception { if (value instanceof String) { value = ((String) value).trim(); } if (typeObject == null) { throw new SQLException("Can't set column because the type is unrecognized"); } if (value == null) { /** If the value is null, set the column value null and return **/ statement.setNull(position, typeObject.intValue()); return; } if ("".equals(value)) { switch (typeObject.intValue()) { case Types.CHAR: case Types.CLOB: case Types.VARCHAR: /** If the value is an empty string and the column is a string type, we can continue **/ break; default: /** If the value is an empty string and the column is something else, we treat it as a null value **/ statement.setNull(position, typeObject.intValue()); return; } } File file = null; int length = -1; InputStream asciiStream = null; //System.out.println("========================================================================"); //System.out.println("JDBCTypeConversions: setting type "+typeObject.intValue()); switch (typeObject.intValue()) { case Types.CLOB: //System.out.println("CLOB"); Clob clob = null; if (value instanceof Clob) { clob = (Clob) value; } else if (value instanceof File) { File asciiFile = (File) value; asciiStream = new BufferedInputStream(new FileInputStream(asciiFile)); length = (int) asciiFile.length(); clob = new ClobHelper(asciiStream, length); } else if (value instanceof Part) { Part anyFile = (Part) value; asciiStream = new BufferedInputStream(anyFile.getInputStream()); length = anyFile.getSize(); clob = new ClobHelper(asciiStream, length); } else if (value instanceof JDBCxlobHelper) { asciiStream = ((JDBCxlobHelper) value).inputStream; length = ((JDBCxlobHelper) value).length; clob = new ClobHelper(asciiStream, length); } else if (value instanceof Source) { asciiStream = ((Source) value).getInputStream(); length = (int) ((Source) value).getContentLength(); clob = new ClobHelper(asciiStream, length); } else { String asciiText = value.toString(); asciiStream = new ByteArrayInputStream(asciiText.getBytes()); length = asciiText.length(); clob = new ClobHelper(asciiStream, length); } statement.setClob(position, clob); break; case Types.CHAR: // simple large object, e.g. Informix's TEXT //System.out.println("CHAR"); if (value instanceof File) { File asciiFile = (File) value; asciiStream = new BufferedInputStream(new FileInputStream(asciiFile)); length = (int) asciiFile.length(); } else if (value instanceof JDBCxlobHelper) { asciiStream = ((JDBCxlobHelper) value).inputStream; length = ((JDBCxlobHelper) value).length; } else if (value instanceof Source) { asciiStream = ((Source) value).getInputStream(); length = (int) ((Source) value).getContentLength(); } else if (value instanceof Part) { Part anyFile = (Part) value; asciiStream = new BufferedInputStream(anyFile.getInputStream()); length = anyFile.getSize(); clob = new ClobHelper(asciiStream, length); } else { String asciiText = value.toString(); asciiStream = new BufferedInputStream(new ByteArrayInputStream(asciiText.getBytes())); length = asciiText.length(); } statement.setAsciiStream(position, asciiStream, length); break; case Types.BIGINT: //System.out.println("BIGINT"); BigDecimal bd = null; if (value instanceof BigDecimal) { bd = (BigDecimal) value; } else if (value instanceof Number) { bd = BigDecimal.valueOf(((Number) value).longValue()); } else { bd = new BigDecimal(value.toString()); } statement.setBigDecimal(position, bd); break; case Types.TINYINT: //System.out.println("TINYINT"); Byte b = null; if (value instanceof Byte) { b = (Byte) value; } else if (value instanceof Number) { b = new Byte(((Number) value).byteValue()); } else { b = new Byte(value.toString()); } statement.setByte(position, b.byteValue()); break; case Types.DATE: //System.out.println("DATE"); Date d = null; if (value instanceof Date) { d = (Date) value; } else if (value instanceof java.util.Date) { d = new Date(((java.util.Date) value).getTime()); } else if (value instanceof Calendar) { d = new Date(((Calendar) value).getTime().getTime()); } else { d = Date.valueOf(value.toString()); } statement.setDate(position, d); break; case Types.DOUBLE: //System.out.println("DOUBLE"); double db; if (value instanceof Number) { db = (((Number) value).doubleValue()); } else { db = Double.parseDouble(value.toString()); } statement.setDouble(position, db); break; case Types.FLOAT: //System.out.println("FLOAT"); float f; if (value instanceof Number) { f = (((Number) value).floatValue()); } else { f = Float.parseFloat(value.toString()); } statement.setFloat(position, f); break; case Types.NUMERIC: //System.out.println("NUMERIC"); long l; if (value instanceof Number) { l = (((Number) value).longValue()); } else { l = Long.parseLong(value.toString()); } statement.setLong(position, l); break; case Types.SMALLINT: //System.out.println("SMALLINT"); Short s = null; if (value instanceof Short) { s = (Short) value; } else if (value instanceof Number) { s = new Short(((Number) value).shortValue()); } else { s = new Short(value.toString()); } statement.setShort(position, s.shortValue()); break; case Types.TIME: //System.out.println("TIME"); Time t = null; if (value instanceof Time) { t = (Time) value; } else if (value instanceof java.util.Date) { t = new Time(((java.util.Date) value).getTime()); } else { t = Time.valueOf(value.toString()); } statement.setTime(position, t); break; case Types.TIMESTAMP: //System.out.println("TIMESTAMP"); Timestamp ts = null; if (value instanceof Time) { ts = (Timestamp) value; } else if (value instanceof java.util.Date) { ts = new Timestamp(((java.util.Date) value).getTime()); } else { ts = Timestamp.valueOf(value.toString()); } statement.setTimestamp(position, ts); break; case Types.ARRAY: //System.out.println("ARRAY"); statement.setArray(position, (Array) value); // no way to convert string to array break; case Types.STRUCT: //System.out.println("STRUCT"); case Types.OTHER: //System.out.println("OTHER"); statement.setObject(position, value); break; case Types.LONGVARBINARY: //System.out.println("LONGVARBINARY"); statement.setTimestamp(position, new Timestamp((new java.util.Date()).getTime())); break; case Types.VARCHAR: //System.out.println("VARCHAR"); statement.setString(position, value.toString()); break; case Types.BLOB: //System.out.println("BLOB"); if (value instanceof JDBCxlobHelper) { statement.setBinaryStream(position, ((JDBCxlobHelper) value).inputStream, ((JDBCxlobHelper) value).length); } else if (value instanceof Source) { statement.setBinaryStream(position, ((Source) value).getInputStream(), (int) ((Source) value).getContentLength()); } else { Blob blob = null; if (value instanceof Blob) { blob = (Blob) value; } else if (value instanceof File) { file = (File) value; blob = new BlobHelper(new FileInputStream(file), (int) file.length()); } else if (value instanceof String) { file = new File((String) value); blob = new BlobHelper(new FileInputStream(file), (int) file.length()); } else if (value instanceof Part) { Part anyFile = (Part) value; blob = new BlobHelper(new BufferedInputStream(anyFile.getInputStream()), anyFile.getSize()); } else { throw new SQLException("Invalid type for blob: " + value.getClass().getName()); } //InputStream input = new BufferedInputStream(new FileInputStream(file)); statement.setBlob(position, blob); } break; case Types.VARBINARY: //System.out.println("VARBINARY"); if (value instanceof JDBCxlobHelper) { statement.setBinaryStream(position, ((JDBCxlobHelper) value).inputStream, ((JDBCxlobHelper) value).length); } else if (value instanceof Source) { statement.setBinaryStream(position, ((Source) value).getInputStream(), (int) ((Source) value).getContentLength()); } else if (value instanceof Part) { statement.setBinaryStream(position, ((Part) value).getInputStream(), ((Part) value).getSize()); } else { if (value instanceof File) { file = (File) value; } else if (value instanceof String) { file = new File((String) value); } else { throw new SQLException("Invalid type for blob: " + value.getClass().getName()); } //InputStream input = new BufferedInputStream(new FileInputStream(file)); FileInputStream input = new FileInputStream(file); statement.setBinaryStream(position, input, (int) file.length()); } break; case Types.INTEGER: //System.out.println("INTEGER"); Integer i = null; if (value instanceof Integer) { i = (Integer) value; } else if (value instanceof Number) { i = new Integer(((Number) value).intValue()); } else { i = new Integer(value.toString()); } statement.setInt(position, i.intValue()); break; case Types.BIT: //System.out.println("BIT"); Boolean bo = null; if (value instanceof Boolean) { bo = (Boolean) value; } else if (value instanceof Number) { bo = BooleanUtils.toBooleanObject(((Number) value).intValue() == 1); } else { bo = BooleanUtils.toBooleanObject(value.toString()); } statement.setBoolean(position, bo.booleanValue()); break; default: //System.out.println("default"); throw new SQLException("Impossible exception - invalid type "); } //System.out.println("========================================================================"); }