java.sql.PreparedStatement#setBigDecimal ( )源码实例Demo

下面列出了java.sql.PreparedStatement#setBigDecimal ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: gemfirexd-oss   文件: TradeSecuritiesDMLStmt.java
protected void insertToSecuritiesFulldataset (Connection conn, int sec_id, String symbol, BigDecimal price, String exchange, int tid){
  //manually update fulldataset table for above entry.
   try{
    
     Log.getLogWriter().info(" Trigger behaviour is not defined for putDML hence deleting  the  row  from TRADE.SECURITIES_FULLDATASET with data SEC_ID:" +  sec_id );
     conn.createStatement().execute("DELETE FROM TRADE.SECURITIES_FULLDATASET  WHERE  sec_id = "  + sec_id );      

    PreparedStatement preparedInsertStmt = conn.prepareStatement("insert into trade.SECURITIES_fulldataset values (?,?,?,?,?)");          
    
    preparedInsertStmt.setInt(1, sec_id);
    preparedInsertStmt.setString(2, symbol);
    preparedInsertStmt.setBigDecimal(3, price);
    preparedInsertStmt.setString(4, exchange);       
    preparedInsertStmt.setInt(5, tid); 
   
    Log.getLogWriter().info(" Trigger behaviour is not defined for putDML hence inserting  the  row  into  TRADE.SECURITIES_FULLDATASET with data SEC_ID:" +  sec_id +  ",SYMBOL" + symbol  + ",EXCHANGE:" +  exchange + ",PRICE:" + price + ".TID:" + tid );
    preparedInsertStmt.executeUpdate();
   } catch (SQLException se) {
     Log.getLogWriter().info("Error while updating TRADE.SECURITIES_FULLDATASET table. It may cause Data inconsistency " + se.getMessage() ); 
   }
}
 
源代码2 项目: AsuraFramework   文件: StdJDBCDelegate.java
/**
 * <p>
 * Update the simple trigger data.
 * </p>
 * 
 * @param conn
 *          the DB Connection
 * @param trigger
 *          the trigger to insert
 * @return the number of rows updated
 */
public int updateSimpleTrigger(Connection conn, SimpleTrigger trigger)
    throws SQLException {
    PreparedStatement ps = null;

    try {
        ps = conn.prepareStatement(rtp(UPDATE_SIMPLE_TRIGGER));

        ps.setInt(1, trigger.getRepeatCount());
        ps.setBigDecimal(2, new BigDecimal(String.valueOf(trigger
                .getRepeatInterval())));
        ps.setInt(3, trigger.getTimesTriggered());
        ps.setString(4, trigger.getName());
        ps.setString(5, trigger.getGroup());

        return ps.executeUpdate();
    } finally {
        closeStatement(ps);
    }
}
 
源代码3 项目: gemfirexd-oss   文件: TradeBuyOrdersDMLTxStmt.java
protected void insertBatchToGFXDTable(Connection conn, int[] oid, int cid, int[] sid, int []qty,
    String status, Timestamp[] time, BigDecimal[] bid) throws SQLException{
  PreparedStatement stmt = conn.prepareStatement(insert);
  int tid = getMyTid();
  int counts[] = null;
  Log.getLogWriter().info("Insert into gemfirexd, myTid is " + tid);
  int size = oid.length;
  for (int i=0; i<size; i++) {
    Log.getLogWriter().info("inserting into table trade.buyorders oid is " + oid[i] +
        " cid is "+ cid + " sid is " + sid[i] + " qty is " + qty[i] + " status is " + status +
        " time is "+ time[i] + " bid is " + bid[i] + " tid is " + tid);
    stmt.setInt(1, oid[i]);
    stmt.setInt(2, cid);
    stmt.setInt(3, sid[i]);
    stmt.setInt(4, qty[i]);
    stmt.setBigDecimal(5, bid[i]);
    stmt.setTimestamp(6, time[i]);
    stmt.setString(7, status);       
    stmt.setInt(8, tid);
    stmt.addBatch();
  }
  
  counts = stmt.executeBatch();   
  
  Log.getLogWriter().info("gfxd inserts " + counts.length + " record");
}
 
源代码4 项目: lams   文件: StdJDBCDelegate.java
/**
 * <p>
 * Get the names of all of the triggers in the given group and state that
 * have misfired.
 * </p>
 * 
 * @param conn
 *          the DB Connection
 * @return an array of <code>{@link
 * org.quartz.utils.Key}</code> objects
 */
public List<TriggerKey> selectMisfiredTriggersInGroupInState(Connection conn,
        String groupName, String state, long ts) throws SQLException {
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        ps = conn
                .prepareStatement(rtp(SELECT_MISFIRED_TRIGGERS_IN_GROUP_IN_STATE));
        ps.setBigDecimal(1, new BigDecimal(String.valueOf(ts)));
        ps.setString(2, groupName);
        ps.setString(3, state);
        rs = ps.executeQuery();

        LinkedList<TriggerKey> list = new LinkedList<TriggerKey>();
        while (rs.next()) {
            String triggerName = rs.getString(COL_TRIGGER_NAME);
            list.add(triggerKey(triggerName, groupName));
        }
        return list;
    } finally {
        closeResultSet(rs);
        closeStatement(ps);
    }
}
 
源代码5 项目: gemfirexd-oss   文件: TradeBuyOrdersDMLTxStmt.java
protected int deleteToTableCidRangeTx(PreparedStatement stmt, int cid, int cid2, 
		int oid, BigDecimal bid, int whichDelete) throws SQLException { 
   int rowCount = 0;
   switch (whichDelete) {
   case 0: 
 		//"delete from trade.buyorders where cid=? and oid=? and bid <?",
     Log.getLogWriter().info("deleting from buyorders table for cid: " + cid 
     		+ " and oid: " + oid + " and bid<" + bid);
     stmt.setInt(1, cid);
     stmt.setInt(2, oid);
     stmt.setBigDecimal(3, bid);
     rowCount = stmt.executeUpdate();
     break;
   case 1: 
     // "delete from trade.buyorders where cid>? and cid<? and status IN ('cancelled', 'filled')",  
     Log.getLogWriter().info("deleting from buyorders table for cid> "+ cid + " to cid< " + cid2 + 
     		" and status IN ('cancelled', 'filled')");
     stmt.setInt(1, cid);
     stmt.setInt(2, cid2);
     rowCount =  stmt.executeUpdate();
    break;
   default:
    throw new TestException ("Wrong update sql string here");
   }
   SQLWarning warning = stmt.getWarnings(); //test to see there is a warning
   if (warning != null) {
     SQLHelper.printSQLWarning(warning);
   } 
   return rowCount;		
}
 
源代码6 项目: jTDS   文件: Tds8Test.java
public void testSqlVariant() throws Exception {
    Statement stmt = con.createStatement();
    stmt.execute("CREATE TABLE #VARTEST (id int, data sql_variant)");
    PreparedStatement pstmt = con.prepareStatement("INSERT INTO #VARTEST (id, data) VALUES (?, ?)");

    pstmt.setInt(1, 1);
    pstmt.setString(2, "TEST STRING");
    assertEquals("Insert 1 failed", pstmt.executeUpdate(), 1);
    pstmt.setInt(1, 2);
    pstmt.setInt(2, 255);
    assertEquals("Insert 2 failed", pstmt.executeUpdate(), 1);
    pstmt.setInt(1, 3);
    pstmt.setBigDecimal(2, new BigDecimal("10.23"));
    assertEquals("Insert 3 failed", pstmt.executeUpdate(), 1);
    pstmt.setInt(1, 4);
    byte bytes[] = {'X', 'X', 'X'};
    pstmt.setBytes(2, bytes);
    assertEquals("Insert 4 failed", pstmt.executeUpdate(), 1);
    ResultSet rs = stmt.executeQuery("SELECT id, data FROM #VARTEST ORDER BY id");
    assertNotNull(rs);
    assertTrue(rs.next());
    assertEquals("TEST STRING", rs.getString(2));
    assertTrue(rs.next());
    assertEquals(255, rs.getInt(2));
    assertTrue(rs.next());
    assertEquals("java.math.BigDecimal", rs.getObject(2).getClass().getName());
    assertEquals("10.23", rs.getString(2));
    assertTrue(rs.next());
    assertEquals("585858", rs.getString(2));
    stmt.close();
    pstmt.close();
}
 
private void updateData(String tableName, int startIndex, int endIndex) throws SQLException {
  PreparedStatement ps = connection.prepareStatement("UPDATE " + tableName + " set blobField=?, charField=?," +
      "charForBitData=?, clobField=?, dateField=?, decimalField=?, doubleField=?, floatField=?, longVarcharForBitDataField=?, numericField=?," +
      "realField=?, smallIntField=?, timeField=?, timestampField=?, varcharField=?, varcharForBitData=?, xmlField=xmlparse(document cast (? as clob) PRESERVE WHITESPACE) where bigIntegerField=?");
 
  for (int i = startIndex; i < endIndex; i++) {
    int lessThan10 = i % 10;

    ps.setBlob(1,new ByteArrayInputStream(new byte[]{(byte)i,(byte)i,(byte)i,(byte)i}));
    ps.setString(2, ""+lessThan10);
    ps.setBytes(3, ("" + lessThan10).getBytes());
    ps.setClob(4, new StringReader("UPDATE CLOB " + i));
    ps.setDate(5, new Date(System.currentTimeMillis()));
    ps.setBigDecimal(6, new BigDecimal(lessThan10 + .8));
    ps.setDouble(7, i + .88);
    ps.setFloat(8, i + .9f);
    ps.setBytes(9, ("B" + lessThan10).getBytes());
    ps.setBigDecimal(10, new BigDecimal(i));
    ps.setFloat(11, lessThan10 * 1111);
    ps.setShort(12, (short)i);
    ps.setTime(13, new Time(System.currentTimeMillis()));
    ps.setTimestamp(14, new Timestamp(System.currentTimeMillis()));
    ps.setString(15, "BY" + lessThan10);
    ps.setBytes(16, ("" + lessThan10).getBytes());
    ps.setClob(17, new StringReader("<xml><sometag>UPDATE XML CLOB " + i + "</sometag></xml>"));
    ps.setLong(18, i);
    ps.execute();
  }
}
 
protected ResultSet getSelectForUpdateRS(PreparedStatement stmt, int cid, int cid2, 
    int sid, BigDecimal ask, Timestamp orderTime, String status, 
    int whichUpdate, int size) throws SQLException {
  
  int txId = (Integer) SQLDistTxTest.curTxId.get();
  String database =  SQLHelper.isDerbyConn(stmt.getConnection()) ? "Derby - " : "gemfirexd - TXID:" + txId + " " ;
  switch (whichUpdate) {
  case 0: 
    //"select oid, status from trade.sellorders where sid = ? and ask>? for update of status ",
    stmt.setInt(1, sid);
    stmt.setBigDecimal(2, ask);
    Log.getLogWriter().info(database + " selecting for update from trade.sellorders with SID:" + sid + ",ASK:" + ask + " QUERY: " +selectForUpdate[whichUpdate]);
    break;
  case 1: 
    // "select * from trade.sellorders where cid >= ? and cid <? for update of qty, status ",
    stmt.setInt(1, cid);
    stmt.setInt(2, cid2);
    Log.getLogWriter().info(database  + "selecting for update from trade.sellorders with 1_CID:" + cid + ",2_CID:" + cid2 +  " QUERY: " +selectForUpdate[whichUpdate]);
    break;
  case 2: //"select * from  trade.sellorders where cid = ? and sid= ? for update ",
    stmt.setInt(1, cid);
    stmt.setInt(2, sid);
    Log.getLogWriter().info(database + "selecting for update from trade.sellorders with CID:" + cid + ",SID:" + sid + " QUERY: " + selectForUpdate[whichUpdate]);
    break;
  default:
    throw new TestException (database + "Wrong select for update sql string here"); 
  }
  return stmt.executeQuery();
}
 
源代码9 项目: gemfirexd-oss   文件: TradeSecuritiesDMLTxStmt.java
protected int updateToTableCidRangeTx(PreparedStatement stmt, int sid,  
		String symbol, BigDecimal price, int whichUpdate) throws SQLException { 
   int rowCount = 0;
   switch (whichUpdate) {
   case 0: 
 		// "update trade.securities set price = ? where sec_id = ?  ", 
     Log.getLogWriter().info("updating price to " + price +
     		", for sec_id: " + sid );
     stmt.setBigDecimal(1, price);
     stmt.setInt(2, sid);  
     rowCount = stmt.executeUpdate();    
     break;
   case 1: 
     //  "update trade.securities set symbol = ? where sec_id = ? ",
     Log.getLogWriter().info("updating symbol to " + symbol +
     		", for sec_id: " + sid );
     stmt.setString(1, symbol);
     stmt.setInt(2, sid);  
     rowCount = stmt.executeUpdate();              
     break;
   case 2: 
    //"update trade.securities set price = ? where sec_id > ? and symbol >? " //multiple records
     Log.getLogWriter().info("updating price to " + price +
     		", for sec_id> " + sid + " and symbol> " + symbol );
     stmt.setBigDecimal(1, price);
     stmt.setInt(2, sid); 
     stmt.setString(3, symbol); 
     rowCount = stmt.executeUpdate();  
     break;
   default:
    throw new TestException ("Wrong update sql string here");
   }
   SQLWarning warning = stmt.getWarnings(); //test to see there is a warning
   if (warning != null) {
     SQLHelper.printSQLWarning(warning);
   } 
   return rowCount;		
}
 
源代码10 项目: AsuraFramework   文件: StdJDBCDelegate.java
/**
 * <p>
 * Get the names of all of the triggers in the given group and state that
 * have misfired.
 * </p>
 * 
 * @param conn
 *          the DB Connection
 * @return an array of <code>{@link
 * org.quartz.utils.Key}</code> objects
 */
public Key[] selectMisfiredTriggersInGroupInState(Connection conn,
        String groupName, String state, long ts) throws SQLException {
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        ps = conn
                .prepareStatement(rtp(SELECT_MISFIRED_TRIGGERS_IN_GROUP_IN_STATE));
        ps.setBigDecimal(1, new BigDecimal(String.valueOf(ts)));
        ps.setString(2, groupName);
        ps.setString(3, state);
        rs = ps.executeQuery();

        ArrayList list = new ArrayList();
        while (rs.next()) {
            String triggerName = rs.getString(COL_TRIGGER_NAME);
            list.add(new Key(triggerName, groupName));
        }
        Object[] oArr = list.toArray();
        Key[] kArr = new Key[oArr.length];
        System.arraycopy(oArr, 0, kArr, 0, oArr.length);
        return kArr;
    } finally {
        closeResultSet(rs);
        closeStatement(ps);
    }
}
 
源代码11 项目: lams   文件: IdentifierGeneratorHelper.java
public void bind(PreparedStatement preparedStatement, int position) throws SQLException {
	preparedStatement.setBigDecimal( position, value );
}
 
源代码12 项目: phoenix   文件: ProductMetricsIT.java
private static void initTableValues(String tablename, Connection conn, String tenantId) throws Exception {
    PreparedStatement stmt = conn.prepareStatement(
            "upsert into " + tablename +
                    " (" +
                    "    ORGANIZATION_ID, " +
                    "    \"DATE\", " +
                    "    FEATURE, " +
                    "    UNIQUE_USERS, " +
                    "    TRANSACTIONS, " +
                    "    CPU_UTILIZATION, " +
                    "    DB_UTILIZATION, " +
                    "    REGION, " +
                    "    IO_TIME)" +
                    "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
    stmt.setString(1, tenantId);
    stmt.setDate(2, D1);
    stmt.setString(3, F1);
    stmt.setInt(4, 10);
    stmt.setLong(5, 100L);
    stmt.setBigDecimal(6, BigDecimal.valueOf(0.5));
    stmt.setBigDecimal(7, BigDecimal.valueOf(0.2));
    stmt.setString(8, R2);
    stmt.setNull(9, Types.BIGINT);
    stmt.execute();

    stmt.setString(1, tenantId);
    stmt.setDate(2, D2);
    stmt.setString(3, F1);
    stmt.setInt(4, 20);
    stmt.setLong(5, 200);
    stmt.setBigDecimal(6, BigDecimal.valueOf(1.0));
    stmt.setBigDecimal(7, BigDecimal.valueOf(0.4));
    stmt.setString(8, null);
    stmt.setLong(9, 2000);
    stmt.execute();

    stmt.setString(1, tenantId);
    stmt.setDate(2, D3);
    stmt.setString(3, F1);
    stmt.setInt(4, 30);
    stmt.setLong(5, 300);
    stmt.setBigDecimal(6, BigDecimal.valueOf(2.5));
    stmt.setBigDecimal(7, BigDecimal.valueOf(0.6));
    stmt.setString(8, R1);
    stmt.setNull(9, Types.BIGINT);
    stmt.execute();

    stmt.setString(1, tenantId);
    stmt.setDate(2, D4);
    stmt.setString(3, F2);
    stmt.setInt(4, 40);
    stmt.setLong(5, 400);
    stmt.setBigDecimal(6, BigDecimal.valueOf(3.0));
    stmt.setBigDecimal(7, BigDecimal.valueOf(0.8));
    stmt.setString(8, R1);
    stmt.setLong(9, 4000);
    stmt.execute();

    stmt.setString(1, tenantId);
    stmt.setDate(2, D5);
    stmt.setString(3, F3);
    stmt.setInt(4, 50);
    stmt.setLong(5, 500);
    stmt.setBigDecimal(6, BigDecimal.valueOf(3.5));
    stmt.setBigDecimal(7, BigDecimal.valueOf(1.2));
    stmt.setString(8, R2);
    stmt.setLong(9, 5000);
    stmt.execute();

    stmt.setString(1, tenantId);
    stmt.setDate(2, D6);
    stmt.setString(3, F1);
    stmt.setInt(4, 60);
    stmt.setLong(5, 600);
    stmt.setBigDecimal(6, BigDecimal.valueOf(4.0));
    stmt.setBigDecimal(7, BigDecimal.valueOf(1.4));
    stmt.setString(8, null);
    stmt.setNull(9, Types.BIGINT);
    stmt.execute();
}
 
public void setSecurities(int i, PreparedStatement ps) throws SQLException  {
  ps.setBigDecimal(i,securities);
}
 
源代码14 项目: phoenix   文件: WriteWorkload.java
private PreparedStatement buildStatement(Scenario scenario, List<Column> columns,
        PreparedStatement statement, SimpleDateFormat simpleDateFormat) throws Exception {
    int count = 1;
    for (Column column : columns) {

        DataValue dataValue = getRulesApplier().getDataForRule(scenario, column);
        switch (column.getType()) {
        case VARCHAR:
            if (dataValue.getValue().equals("")) {
                statement.setNull(count, Types.VARCHAR);
            } else {
                statement.setString(count, dataValue.getValue());
            }
            break;
        case CHAR:
            if (dataValue.getValue().equals("")) {
                statement.setNull(count, Types.CHAR);
            } else {
                statement.setString(count, dataValue.getValue());
            }
            break;
        case DECIMAL:
            if (dataValue.getValue().equals("")) {
                statement.setNull(count, Types.DECIMAL);
            } else {
                statement.setBigDecimal(count, new BigDecimal(dataValue.getValue()));
            }
            break;
        case INTEGER:
            if (dataValue.getValue().equals("")) {
                statement.setNull(count, Types.INTEGER);
            } else {
                statement.setInt(count, Integer.parseInt(dataValue.getValue()));
            }
            break;
        case UNSIGNED_LONG:
            if (dataValue.getValue().equals("")) {
                statement.setNull(count, Types.OTHER);
            } else {
                statement.setLong(count, Long.parseLong(dataValue.getValue()));
            }
            break;
        case BIGINT:
            if (dataValue.getValue().equals("")) {
                statement.setNull(count, Types.BIGINT);
            } else {
                statement.setLong(count, Long.parseLong(dataValue.getValue()));
            }
            break;
        case TINYINT:
            if (dataValue.getValue().equals("")) {
                statement.setNull(count, Types.TINYINT);
            } else {
                statement.setLong(count, Integer.parseInt(dataValue.getValue()));
            }
            break;
        case DATE:
            if (dataValue.getValue().equals("")) {
                statement.setNull(count, Types.DATE);
            } else {
                Date
                        date =
                        new java.sql.Date(simpleDateFormat.parse(dataValue.getValue()).getTime());
                statement.setDate(count, date);
            }
            break;
        case VARCHAR_ARRAY:
            if (dataValue.getValue().equals("")) {
                statement.setNull(count, Types.ARRAY);
            } else {
                Array
                        arr =
                        statement.getConnection().createArrayOf("VARCHAR", dataValue.getValue().split(","));
                statement.setArray(count, arr);
            }
        	break;
        case VARBINARY:
            if (dataValue.getValue().equals("")) {
                statement.setNull(count, Types.VARBINARY);
            } else {
                statement.setBytes(count, dataValue.getValue().getBytes());
            }
            break;
        case TIMESTAMP:
            if (dataValue.getValue().equals("")) {
                statement.setNull(count, Types.TIMESTAMP);
            } else {
                java.sql.Timestamp
                        ts =
                        new java.sql.Timestamp(simpleDateFormat.parse(dataValue.getValue()).getTime());
                statement.setTimestamp(count, ts);
            }
            break;
        default:
            break;
        }
        count++;
    }
    return statement;
}
 
源代码15 项目: AsuraFramework   文件: PointbaseDelegate.java
public int updateTrigger(Connection conn, Trigger trigger, String state,
        JobDetail jobDetail) throws SQLException, IOException {

    ByteArrayOutputStream baos = serializeJobData(trigger.getJobDataMap());
    int len = baos.toByteArray().length;
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            
    PreparedStatement ps = null;

    int insertResult = 0;


    try {
        ps = conn.prepareStatement(rtp(UPDATE_TRIGGER));
            
        ps.setString(1, trigger.getJobName());
        ps.setString(2, trigger.getJobGroup());
        setBoolean(ps, 3, trigger.isVolatile());
        ps.setString(4, trigger.getDescription());
        long nextFireTime = -1;
        if (trigger.getNextFireTime() != null) {
            nextFireTime = trigger.getNextFireTime().getTime();
        }
        ps.setBigDecimal(5, new BigDecimal(String.valueOf(nextFireTime)));
        long prevFireTime = -1;
        if (trigger.getPreviousFireTime() != null) {
            prevFireTime = trigger.getPreviousFireTime().getTime();
        }
        ps.setBigDecimal(6, new BigDecimal(String.valueOf(prevFireTime)));
        ps.setString(7, state);
        if (trigger instanceof SimpleTrigger && ((SimpleTrigger)trigger).hasAdditionalProperties() == false ) {
            //                updateSimpleTrigger(conn, (SimpleTrigger)trigger);
            ps.setString(8, TTYPE_SIMPLE);
        } else if (trigger instanceof CronTrigger && ((CronTrigger)trigger).hasAdditionalProperties() == false ) {
            //                updateCronTrigger(conn, (CronTrigger)trigger);
            ps.setString(8, TTYPE_CRON);
        } else {
            //                updateBlobTrigger(conn, trigger);
            ps.setString(8, TTYPE_BLOB);
        }
        ps.setBigDecimal(9, new BigDecimal(String.valueOf(trigger
                .getStartTime().getTime())));
        long endTime = 0;
        if (trigger.getEndTime() != null) {
            endTime = trigger.getEndTime().getTime();
        }
        ps.setBigDecimal(10, new BigDecimal(String.valueOf(endTime)));
        ps.setString(11, trigger.getCalendarName());
        ps.setInt(12, trigger.getMisfireInstruction());
        
        ps.setInt(13, trigger.getPriority());
        ps.setBinaryStream(14, bais, len);
        ps.setString(15, trigger.getName());
        ps.setString(16, trigger.getGroup());

        insertResult = ps.executeUpdate();
    } finally {
        closeStatement(ps);
    }

    if (insertResult > 0) {
        deleteTriggerListeners(conn, trigger.getName(), trigger.getGroup());

        String[] trigListeners = trigger.getTriggerListenerNames();
        for (int i = 0; trigListeners != null && i < trigListeners.length; i++) {
            insertTriggerListener(conn, trigger, trigListeners[i]);
        }
    }

    return insertResult;
}
 
public void setCash(int i, PreparedStatement ps) throws SQLException  {
  ps.setBigDecimal(i,cash);
}
 
源代码17 项目: phoenix   文件: ArrayIT.java
private static void initTablesWithArrays(String tenantId, Date date, Long ts, boolean useNull, String url) throws Exception {
    Properties props = new Properties();
    if (ts != null) {
        props.setProperty(CURRENT_SCN_ATTRIB, ts.toString());
    }
    Connection conn = DriverManager.getConnection(url, props);
    try {
        // Insert all rows at ts
        PreparedStatement stmt = conn.prepareStatement(
                "upsert into " +
                        "TABLE_WITH_ARRAY(" +
                        "    ORGANIZATION_ID, " +
                        "    ENTITY_ID, " +
                        "    a_string_array, " +
                        "    B_STRING, " +
                        "    A_INTEGER, " +
                        "    A_DATE, " +
                        "    X_DECIMAL, " +
                        "    x_long_array, " +
                        "    X_INTEGER," +
                        "    a_byte_array," +
                        "    A_SHORT," +
                        "    A_FLOAT," +
                        "    a_double_array," +
                        "    A_UNSIGNED_FLOAT," +
                        "    A_UNSIGNED_DOUBLE)" +
                "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
        stmt.setString(1, tenantId);
        stmt.setString(2, ROW1);
        // Need to support primitive
        String[] strArr =  new String[4];
        strArr[0] = "ABC";
        if (useNull) {
            strArr[1] = null;
        } else {
            strArr[1] = "CEDF";
        }
        strArr[2] = "XYZWER";
        strArr[3] = "AB";
        Array array = conn.createArrayOf("VARCHAR", strArr);
        stmt.setArray(3, array);
        stmt.setString(4, B_VALUE);
        stmt.setInt(5, 1);
        stmt.setDate(6, date);
        stmt.setBigDecimal(7, null);
        // Need to support primitive
        Long[] longArr =  new Long[2];
        longArr[0] = 25l;
        longArr[1] = 36l;
        array = conn.createArrayOf("BIGINT", longArr);
        stmt.setArray(8, array);
        stmt.setNull(9, Types.INTEGER);
        // Need to support primitive
        Byte[] byteArr =  new Byte[2];
        byteArr[0] = 25;
        byteArr[1] = 36;
        array = conn.createArrayOf("TINYINT", byteArr);
        stmt.setArray(10, array);
        stmt.setShort(11, (short) 128);
        stmt.setFloat(12, 0.01f);
        // Need to support primitive
        Double[] doubleArr =  new Double[4];
        doubleArr[0] = 25.343;
        doubleArr[1] = 36.763;
        doubleArr[2] = 37.56;
        doubleArr[3] = 386.63;
        array = conn.createArrayOf("DOUBLE", doubleArr);
        stmt.setArray(13, array);
        stmt.setFloat(14, 0.01f);
        stmt.setDouble(15, 0.0001);
        stmt.execute();

        conn.commit();
    } finally {
        conn.close();
    }
}
 
public static ResultSet getNonUniqQuery(Connection conn, int whichQuery, int cid,
    BigDecimal price1, BigDecimal price2, int tid, boolean[] success) {
  PreparedStatement stmt;
  ResultSet rs = null;
  success[0] = true;
  try {
    Boolean hasHdfs = TestConfig.tab().booleanAt(SQLPrms.hasHDFS, false);      
    String database = SQLHelper.isDerbyConn(conn)?"Derby - " :"gemfirexd - ";        
    String query = (! SQLHelper.isDerbyConn(conn) && hasHdfs ) ? " QUERY: " +  nonUniqSelectHdfs[whichQuery] : " QUERY: " +  nonUniqSelect[whichQuery];        
    stmt = (! SQLHelper.isDerbyConn(conn) && hasHdfs )  ? conn.prepareStatement(nonUniqSelectHdfs[whichQuery]) :  conn.prepareStatement(nonUniqSelect[whichQuery]) ; 
    
    switch (whichQuery){
    case 0:
      Log.getLogWriter().info(database + "Querying CustomerSecuritiesNetworth with no data " + query);
      break;
    case 1:
      Log.getLogWriter().info(database + "Querying CustomerSecuritiesNetworth with CID:" + cid + query);
      stmt.setInt(1, cid);
      break;

    case 2:
      Log.getLogWriter().info(database + "Querying CustomerSecuritiesNetworth with CID:" + cid + ",PRICE:"+ price1 + query);
      stmt.setInt(1, cid); //set cid<=?
      stmt.setBigDecimal(2, price1);
      break;

    case 3:
      //"select cid, sid, symbol, exchange, price, subtotal from trade.securities s, trade.portfolio f where sec_id = f.sid and cid >? and (subtotal >10000 or (price >= ? and price <= ?) and f.tid = ?"
      Log.getLogWriter().info(database + "Querying CustomerSecuritiesNetworth with CID:" + cid + ",1_PRICE:"+ price1 + ",2_PRICE:" + price2 + ",TID:"+ tid + query);
      stmt.setInt(1, cid); //set cid>?
      stmt.setBigDecimal(2, price1);
      stmt.setBigDecimal(3, price2);
      break;

    default:
      throw new TestException("incorrect select statement, should not happen");
    }
    rs = stmt.executeQuery();
  } catch (SQLException se) {
    if (!SQLHelper.checkDerbyException(conn, se)) success[0] = false; //handle lock could not acquire or deadlock
    else if (se.getSQLState().equals("0A000") && se.getMessage().matches(".*disk.*")) {
      SQLHelper.printSQLException(se);
      Log.getLogWriter().info("got the unsupported exception, need to remove this once bug#40348 is fixed, continuing test");
      useDisk[0] = true;
      return null;
    }
    else      SQLHelper.handleSQLException(se);
  }
  return rs;
}
 
public void setBid(int i, PreparedStatement ps) throws SQLException  {
  ps.setBigDecimal(i,bid);
}
 
源代码20 项目: lams   文件: IdentifierGeneratorHelper.java
public void bind(PreparedStatement preparedStatement, int position) throws SQLException {
	preparedStatement.setBigDecimal( position, new BigDecimal( value ) );
}