public void bind(PreparedStatement preparedStatement, int position) throws SQLException { preparedStatement.setBigDecimal( position, new BigDecimal( value ) ); }
public List<TriggerKey> selectMisfiredTriggersInState(Connection conn, String state, long ts) throws SQLException { PreparedStatement ps = null; ResultSet rs = null; try { ps = conn.prepareStatement(rtp(SELECT_MISFIRED_TRIGGERS_IN_STATE)); ps.setBigDecimal(1, new BigDecimal(String.valueOf(ts))); ps.setString(2, state); rs = ps.executeQuery(); LinkedList<TriggerKey> list = new LinkedList<TriggerKey>(); while (rs.next()) { String triggerName = rs.getString(COL_TRIGGER_NAME); String groupName = rs.getString(COL_TRIGGER_GROUP); list.add(triggerKey(triggerName, groupName)); } return list; } finally { closeResultSet(rs); closeStatement(ps); } }
ps.setString(paramIndex, inValue.toString()); ps.setString(paramIndex, strVal); ps.setBigDecimal(paramIndex, (BigDecimal) inValue); "Oracle".equals(ps.getConnection().getMetaData().getDatabaseProductName()))) { if (isStringValue(inValue.getClass())) { ps.setString(paramIndex, inValue.toString());
/** * <p> * Get the names of all of the triggers that have misfired. * </p> * * @param conn * the DB Connection * @return an array of <code>{@link * org.quartz.utils.Key}</code> objects */ public List<TriggerKey> selectMisfiredTriggers(Connection conn, long ts) throws SQLException { PreparedStatement ps = null; ResultSet rs = null; try { ps = conn.prepareStatement(rtp(SELECT_MISFIRED_TRIGGERS)); ps.setBigDecimal(1, new BigDecimal(String.valueOf(ts))); rs = ps.executeQuery(); LinkedList<TriggerKey> list = new LinkedList<TriggerKey>(); while (rs.next()) { String triggerName = rs.getString(COL_TRIGGER_NAME); String groupName = rs.getString(COL_TRIGGER_GROUP); list.add(triggerKey(triggerName, groupName)); } return list; } finally { closeResultSet(rs); closeStatement(ps); } }
try (PreparedStatement statement = connection.prepareStatement( "INSERT INTO test_execute_update VALUES (?, ?, ?, ?, ?, ?, ?)")) { statement.setBoolean(1, true); statement.setLong(2, 5L); statement.setDouble(3, 7.0d); statement.setBigDecimal(4, BigDecimal.valueOf(8L)); statement.setString(5, "abc'xyz"); statement.setBytes(6, "xyz".getBytes(UTF_8)); statement.setNull(7, Types.BIGINT);
Object param = parameterValues[inputSplit.getSplitNumber()][i]; if (param instanceof String) { statement.setString(i + 1, (String) param); } else if (param instanceof Long) { statement.setLong(i + 1, (Long) param); } else if (param instanceof Integer) { statement.setInt(i + 1, (Integer) param); } else if (param instanceof Double) { statement.setDouble(i + 1, (Double) param); statement.setFloat(i + 1, (Float) param); } else if (param instanceof BigDecimal) { statement.setBigDecimal(i + 1, (BigDecimal) param); } else if (param instanceof Byte) { statement.setByte(i + 1, (Byte) param);
private void testSignedNumberSpec(Connection conn, double data) throws Exception { updateSignedTable(conn, data); ResultSet rs = conn.createStatement() .executeQuery("SELECT ABS(\"DEC\"),ABS(doub),ABS(fl),ABS(inte),ABS(lon),ABS(smalli),ABS(tinyi) FROM " + TABLE_NAME); assertTrue(rs.next()); Double d = Double.valueOf(data); assertEquals(rs.getBigDecimal(1).compareTo(BigDecimal.valueOf(data).abs()), 0); assertEquals(rs.getDouble(2), Math.abs(data), 1e-6); assertEquals(rs.getFloat(3), Math.abs(d.floatValue()), 1e-6); assertEquals(rs.getInt(4), Math.abs(d.intValue())); assertEquals(rs.getLong(5), Math.abs(d.longValue())); assertEquals(rs.getShort(6), Math.abs(d.shortValue())); assertEquals(rs.getByte(7), Math.abs(d.byteValue())); assertTrue(!rs.next()); PreparedStatement stmt = conn.prepareStatement("SELECT k FROM " + TABLE_NAME + " WHERE ABS(\"DEC\")=? AND ABS(doub)=? AND ABS(fl)=? AND ABS(inte)=? AND ABS(lon)=? AND ABS(smalli)=? AND ABS(tinyi)=?"); stmt.setBigDecimal(1, BigDecimal.valueOf(data).abs()); stmt.setDouble(2, Math.abs(d.doubleValue())); stmt.setFloat(3, Math.abs(d.floatValue())); stmt.setInt(4, Math.abs(d.intValue())); stmt.setLong(5, Math.abs(d.longValue())); stmt.setShort(6, (short) Math.abs(d.shortValue())); stmt.setByte(7, (byte) Math.abs(d.byteValue())); rs = stmt.executeQuery(); assertTrue(rs.next()); assertEquals(KEY, rs.getString(1)); assertTrue(!rs.next()); }
statement.setInt(parameterIndex, score.getInitScore()); Number[] levelNumbers = score.toLevelNumbers(); if (levelNumbers.length != levelsSize) { statement.setInt(parameterIndex + i + 1, (Integer) levelNumbers[i]); } else if (type == LongType.INSTANCE) { statement.setLong(parameterIndex + i + 1, (Long) levelNumbers[i]); statement.setDouble(parameterIndex + i + 1, (Double) levelNumbers[i]); } else if (type == BigDecimalType.INSTANCE) { statement.setBigDecimal(parameterIndex + i + 1, (BigDecimal) levelNumbers[i]); } else { throw new IllegalStateException("The type (" + type + ") is not yet supported.");
public List<TriggerKey> selectMisfiredTriggersInState(Connection conn, String state, long ts) throws SQLException { PreparedStatement ps = null; ResultSet rs = null; try { ps = conn.prepareStatement(rtp(SELECT_MISFIRED_TRIGGERS_IN_STATE)); ps.setBigDecimal(1, new BigDecimal(String.valueOf(ts))); ps.setString(2, state); rs = ps.executeQuery(); LinkedList<TriggerKey> list = new LinkedList<TriggerKey>(); while (rs.next()) { String triggerName = rs.getString(COL_TRIGGER_NAME); String groupName = rs.getString(COL_TRIGGER_GROUP); list.add(triggerKey(triggerName, groupName)); } return list; } finally { closeResultSet(rs); closeStatement(ps); } }
/** * <p> * Get the names of all of the triggers that have misfired. * </p> * * @param conn * the DB Connection * @return an array of <code>{@link * org.quartz.utils.Key}</code> objects */ public List<TriggerKey> selectMisfiredTriggers(Connection conn, long ts) throws SQLException { PreparedStatement ps = null; ResultSet rs = null; try { ps = conn.prepareStatement(rtp(SELECT_MISFIRED_TRIGGERS)); ps.setBigDecimal(1, new BigDecimal(String.valueOf(ts))); rs = ps.executeQuery(); LinkedList<TriggerKey> list = new LinkedList<TriggerKey>(); while (rs.next()) { String triggerName = rs.getString(COL_TRIGGER_NAME); String groupName = rs.getString(COL_TRIGGER_GROUP); list.add(triggerKey(triggerName, groupName)); } return list; } finally { closeResultSet(rs); closeStatement(ps); } }
public void set(PreparedStatement stat, Object obj, int i) throws SQLException { if (null == obj) { stat.setNull(i, Types.BIGINT); } else { BigDecimal v; if (obj instanceof BigDecimal) v = (BigDecimal) obj; else if (obj instanceof Number) v = BigDecimal.valueOf(((Number) obj).longValue()); else v = new BigDecimal(obj.toString()); stat.setBigDecimal(i, v); } } };
@BeforeClass public static void initTable() throws Exception { String testString = "abc"; Connection conn = null; PreparedStatement stmt = null; try { conn = DriverManager.getConnection(getUrl()); String ddl = "CREATE TABLE IF NOT EXISTS ROUND_DATE_TIME_TS_DECIMAL (s VARCHAR NOT NULL PRIMARY KEY, dt DATE, t TIME, ts TIMESTAMP, dec DECIMAL)"; conn.createStatement().execute(ddl); Date dateUpserted = DateUtil.parseDate("2012-01-01 14:25:28"); dateUpserted = new Date(dateUpserted.getTime() + millisPart); // this makes the dateUpserted equivalent to 2012-01-01 14:25:28.660 long millis = dateUpserted.getTime(); Time timeUpserted = new Time(millis); Timestamp tsUpserted = DateUtil.getTimestamp(millis, nanosPart); stmt = conn.prepareStatement("UPSERT INTO ROUND_DATE_TIME_TS_DECIMAL VALUES (?, ?, ?, ?, ?)"); stmt.setString(1, testString); stmt.setDate(2, dateUpserted); stmt.setTime(3, timeUpserted); stmt.setTimestamp(4, tsUpserted); stmt.setBigDecimal(5, decimalUpserted); stmt.executeUpdate(); conn.commit(); } finally { closeStmtAndConn(stmt, conn); } }
case java.sql.Types.LONGVARCHAR: case java.sql.Types.LONGNVARCHAR: upload.setString(index + 1, (String) row.getField(index)); break; case java.sql.Types.TINYINT: break; case java.sql.Types.INTEGER: upload.setInt(index + 1, (int) row.getField(index)); break; case java.sql.Types.BIGINT: case java.sql.Types.DECIMAL: case java.sql.Types.NUMERIC: upload.setBigDecimal(index + 1, (java.math.BigDecimal) row.getField(index)); break; case java.sql.Types.DATE:
@Override public void nullSafeSet( PreparedStatement statement, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { if ( value == null ) { statement.setNull( index, Types.NUMERIC ); statement.setNull( index + 1, Types.VARCHAR ); } else { MonetaryAmount currency = (MonetaryAmount) value; statement.setBigDecimal( index, currency.getValue() ); statement.setString( index + 1, currency.getCurrency().getCurrencyCode() ); } }
/** * <p> * Get the number of triggers in the given states that have * misfired - according to the given timestamp. * </p> * * @param conn the DB Connection */ public int countMisfiredTriggersInState( Connection conn, String state1, long ts) throws SQLException { PreparedStatement ps = null; ResultSet rs = null; try { ps = conn.prepareStatement(rtp(COUNT_MISFIRED_TRIGGERS_IN_STATE)); ps.setBigDecimal(1, new BigDecimal(String.valueOf(ts))); ps.setString(2, state1); rs = ps.executeQuery(); if (rs.next()) { return rs.getInt(1); } throw new SQLException("No misfired trigger count returned."); } finally { closeResultSet(rs); closeStatement(ps); } }
/** * @throws Exception If failed. */ @Test public void testBigDecimal() throws Exception { stmt = conn.prepareStatement("select * from TestObject where bigVal is not distinct from ?"); stmt.setBigDecimal(1, new BigDecimal(1)); ResultSet rs = stmt.executeQuery(); int cnt = 0; while (rs.next()) { if (cnt == 0) assert rs.getInt("id") == 1; cnt++; } assert cnt == 1; stmt.setNull(1, OTHER); rs = stmt.executeQuery(); cnt = 0; while (rs.next()) { if (cnt == 0) assert rs.getInt("id") == 2; cnt++; } assert cnt == 1; }
@Override public void setNonNullParameter(PreparedStatement ps, int i, BigInteger parameter, JdbcType jdbcType) throws SQLException { ps.setBigDecimal(i, new BigDecimal(parameter)); }
Timestamp tsUpserted = DateUtil.getTimestamp(millis, nanosPart); stmt = conn.prepareStatement( "UPSERT INTO " + tableName + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, testString); stmt.setDate(2, dateUpserted); stmt.setTime(3, timeUpserted); stmt.setTimestamp(4, tsUpserted); stmt.setBigDecimal(5, decimalUpserted); stmt.setDouble(6, doubleUpserted); stmt.setDouble(7, unsignedDoubleUpserted);
statement.setInt(parameter, toIntExact(type.getLong(block, position))); statement.setBigDecimal(parameter, readBigDecimal((DecimalType) type, block, position)); statement.setString(parameter, type.getSlice(block, position).toStringUtf8());
preparedStatement.setString( index, getString( data ) ); } else { String string = getString( data ); preparedStatement.setCharacterStream( index, new StringReader( string ), string.length() ); } else { preparedStatement.setString( index, string ); preparedStatement.setString( index, getBoolean( data ).booleanValue() ? "Y" : "N" ); } else { preparedStatement.setNull( index, java.sql.Types.CHAR ); case ValueMetaInterface.TYPE_BIGNUMBER: if ( !isNull( data ) ) { preparedStatement.setBigDecimal( index, getBigNumber( data ) ); } else { preparedStatement.setNull( index, java.sql.Types.DECIMAL );