public void testNumeric() throws Throwable { CallableStatement call = con.prepareCall("{ call Numeric_Proc(?,?,?) }"); call.registerOutParameter(1, Types.NUMERIC, 15); call.registerOutParameter(2, Types.NUMERIC, 15); call.registerOutParameter(3, Types.NUMERIC, 15); call.executeUpdate(); java.math.BigDecimal ret = call.getBigDecimal(1); assertTrue( "correct return from getNumeric () should be 999999999999999.000000000000000 but returned " + ret.toString(), ret.equals(new java.math.BigDecimal("999999999999999.000000000000000"))); ret = call.getBigDecimal(2); assertTrue( "correct return from getNumeric ()", ret.equals(new java.math.BigDecimal("0.000000000000001"))); try { ret = call.getBigDecimal(3); } catch (NullPointerException ex) { assertTrue("This should be null", call.wasNull()); } }
private static double getBigDecimalAsDouble( CallableStatement CallStatmt, boolean useNamedParameters, String paramName, int ColIndex) throws SQLException { // The PointBase driver will throw an exception if getDouble() // is called for these types so we need to call getBigDecimal() instead. BigDecimal bd; if (useNamedParameters) bd = CallStatmt.getBigDecimal(paramName); else bd = CallStatmt.getBigDecimal(ColIndex); if (bd == null) return 0; return bd.doubleValue(); }
/* (non-Javadoc) * @see pe.com.logistica.negocio.dao.ServicioNegocioDao#calcularCuota(pe.com.logistica.bean.negocio.ServicioAgencia) */ @Override public BigDecimal calcularCuota(ServicioAgencia servicioAgencia) throws SQLException { BigDecimal resultado = BigDecimal.ZERO; Connection conn = null; CallableStatement cs = null; String sql = "{ ? = call negocio.fn_calcularcuota(?,?,?) }"; try { conn = UtilConexion.obtenerConexion(); cs = conn.prepareCall(sql); int i = 1; cs.registerOutParameter(i++, Types.DECIMAL); cs.setBigDecimal(i++, servicioAgencia.getMontoTotalServicios()); cs.setBigDecimal(i++, UtilParse.parseIntABigDecimal(servicioAgencia.getNroCuotas())); cs.setBigDecimal(i++, servicioAgencia.getTea()); cs.execute(); resultado = cs.getBigDecimal(1); } catch (SQLException e) { throw new SQLException(e); } finally { try { if (cs != null) { cs.close(); } if (conn != null) { conn.close(); } } catch (SQLException e) { throw new SQLException(e); } } return resultado; }
public BigDecimal getBigDecimal(String parameterName) throws SQLException { checkOpen(); try { return _stmt.getBigDecimal(parameterName); } catch (SQLException e) { handleException(e); return null; } }
/** @deprecated */ public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException { checkOpen(); try { return _stmt.getBigDecimal(parameterIndex, scale); } catch (SQLException e) { handleException(e); return null; } }
/** The big decimal value */ @Override public BigDecimal getBigDecimal(int i) throws SQLException { try { return _cstmt.getBigDecimal(i); } catch (SQLException e) { onSqlException(e); throw e; } catch (RuntimeException e) { onRuntimeException(e); throw e; } }
/** The big decimal value */ @Override @SuppressWarnings("deprecation") public BigDecimal getBigDecimal(int i, int scale) throws SQLException { try { return _cstmt.getBigDecimal(i, scale); } catch (SQLException e) { onSqlException(e); throw e; } catch (RuntimeException e) { onRuntimeException(e); throw e; } }
/** Test of getBigDecimal method, of inteface java.sql.CallableStatement. */ public void testGetBigDecimal() throws Exception { println("getBigDecimal"); if (!isTestOutParameters()) { return; } CallableStatement stmt; BigDecimal expResult = new BigDecimal("1.00"); BigDecimal result = null; try { stmt = prepRegAndExec("{?= call cast(1.00 as decimal(3,2))}", 1, Types.DECIMAL); result = stmt.getBigDecimal(1); } catch (Exception ex) { fail(ex.getMessage()); } assertEquals(expResult, result); }
@SuppressWarnings("unchecked") public static <T> T getFromStatement(ExecuteContext ctx, Class<? extends T> type, int index) throws SQLException { CallableStatement stmt = (CallableStatement) ctx.statement(); if (type == Blob.class) { return (T) stmt.getBlob(index); } else if (type == Boolean.class) { return (T) checkWasNull(stmt, Boolean.valueOf(stmt.getBoolean(index))); } else if (type == BigInteger.class) { BigDecimal result = stmt.getBigDecimal(index); return (T) (result == null ? null : result.toBigInteger()); } else if (type == BigDecimal.class) { return (T) stmt.getBigDecimal(index); } else if (type == Byte.class) { return (T) checkWasNull(stmt, Byte.valueOf(stmt.getByte(index))); } else if (type == byte[].class) { return (T) stmt.getBytes(index); } else if (type == Clob.class) { return (T) stmt.getClob(index); } else if (type == Date.class) { return (T) stmt.getDate(index); } else if (type == Double.class) { return (T) checkWasNull(stmt, Double.valueOf(stmt.getDouble(index))); } else if (type == Float.class) { return (T) checkWasNull(stmt, Float.valueOf(stmt.getFloat(index))); } else if (type == Integer.class) { return (T) checkWasNull(stmt, Integer.valueOf(stmt.getInt(index))); } else if (type == Long.class) { return (T) checkWasNull(stmt, Long.valueOf(stmt.getLong(index))); } else if (type == Short.class) { return (T) checkWasNull(stmt, Short.valueOf(stmt.getShort(index))); } else if (type == String.class) { return (T) stmt.getString(index); } else if (type == Time.class) { return (T) stmt.getTime(index); } else if (type == Timestamp.class) { return (T) stmt.getTimestamp(index); } else if (type == YearToMonth.class) { if (ctx.getDialect() == POSTGRES) { Object object = stmt.getObject(index); return (T) (object == null ? null : PostgresUtils.toYearToMonth(object)); } else { String string = stmt.getString(index); return (T) (string == null ? null : YearToMonth.valueOf(string)); } } else if (type == DayToSecond.class) { if (ctx.getDialect() == POSTGRES) { Object object = stmt.getObject(index); return (T) (object == null ? null : PostgresUtils.toDayToSecond(object)); } else { String string = stmt.getString(index); return (T) (string == null ? null : DayToSecond.valueOf(string)); } } else if (type == UByte.class) { String string = stmt.getString(index); return (T) (string == null ? null : UByte.valueOf(string)); } else if (type == UShort.class) { String string = stmt.getString(index); return (T) (string == null ? null : UShort.valueOf(string)); } else if (type == UInteger.class) { String string = stmt.getString(index); return (T) (string == null ? null : UInteger.valueOf(string)); } else if (type == ULong.class) { String string = stmt.getString(index); return (T) (string == null ? null : ULong.valueOf(string)); } // The type byte[] is handled earlier. byte[][] can be handled here else if (type.isArray()) { return (T) convertArray(stmt.getObject(index), (Class<? extends Object[]>) type); } else if (ArrayRecord.class.isAssignableFrom(type)) { return (T) getArrayRecord(ctx, stmt.getArray(index), (Class<? extends ArrayRecord<?>>) type); } else if (EnumType.class.isAssignableFrom(type)) { return getEnumType(type, stmt.getString(index)); } else if (MasterDataType.class.isAssignableFrom(type)) { return (T) getMasterDataType(type, stmt.getString(index)); } else if (UDTRecord.class.isAssignableFrom(type)) { switch (ctx.getDialect()) { case POSTGRES: return (T) pgNewUDTRecord(type, stmt.getObject(index)); } return (T) stmt.getObject(index, DataTypes.udtRecords()); } else if (Result.class.isAssignableFrom(type)) { ResultSet nested = (ResultSet) stmt.getObject(index); return (T) getNewFactory(ctx).fetch(nested); } else { return (T) stmt.getObject(index); } }
/** @see java.sql.CallableStatement#getBigDecimal(java.lang.String) */ public BigDecimal getBigDecimal(String parameterName) throws SQLException { return original.getBigDecimal(parameterName); }
/** * @see java.sql.CallableStatement#getBigDecimal(int, int) * @deprecated */ public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException { return original.getBigDecimal(parameterIndex, scale); }
public BigDecimal getBigDecimal(String parameterName) throws SQLException { return passThru.getBigDecimal(parameterName); }
public BigDecimal getBigDecimal(int parameterIndex) throws SQLException { return passThru.getBigDecimal(parameterIndex); }