Example usage for java.sql PreparedStatement setBigDecimal

List of usage examples for java.sql PreparedStatement setBigDecimal

Introduction

In this page you can find the example usage for java.sql PreparedStatement setBigDecimal.

Prototype

void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given java.math.BigDecimal value.

Usage

From source file:org.apache.phoenix.end2end.DateTimeIT.java

private String initAtable() throws SQLException {
    String tableName = generateUniqueName();
    ensureTableCreated(getUrl(), tableName, ATABLE_NAME, (byte[][]) null, null);
    PreparedStatement stmt = conn.prepareStatement("upsert into " + tableName + "(" + "    ORGANIZATION_ID, "
            + "    ENTITY_ID, " + "    A_STRING, " + "    B_STRING, " + "    A_INTEGER, " + "    A_DATE, "
            + "    X_DECIMAL, " + "    X_LONG, " + "    X_INTEGER," + "    Y_INTEGER," + "    A_BYTE,"
            + "    A_SHORT," + "    A_FLOAT," + "    A_DOUBLE," + "    A_UNSIGNED_FLOAT,"
            + "    A_UNSIGNED_DOUBLE)" + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
    stmt.setString(1, tenantId);//from   ww w.ja  va  2s .  co  m
    stmt.setString(2, ROW1);
    stmt.setString(3, A_VALUE);
    stmt.setString(4, B_VALUE);
    stmt.setInt(5, 1);
    stmt.setDate(6, date);
    stmt.setBigDecimal(7, null);
    stmt.setNull(8, Types.BIGINT);
    stmt.setNull(9, Types.INTEGER);
    stmt.setNull(10, Types.INTEGER);
    stmt.setByte(11, (byte) 1);
    stmt.setShort(12, (short) 128);
    stmt.setFloat(13, 0.01f);
    stmt.setDouble(14, 0.0001);
    stmt.setFloat(15, 0.01f);
    stmt.setDouble(16, 0.0001);
    stmt.execute();

    stmt.setString(1, tenantId);
    stmt.setString(2, ROW2);
    stmt.setString(3, A_VALUE);
    stmt.setString(4, C_VALUE);
    stmt.setInt(5, 2);
    stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1));
    stmt.setBigDecimal(7, null);
    stmt.setNull(8, Types.BIGINT);
    stmt.setNull(9, Types.INTEGER);
    stmt.setNull(10, Types.INTEGER);
    stmt.setByte(11, (byte) 2);
    stmt.setShort(12, (short) 129);
    stmt.setFloat(13, 0.02f);
    stmt.setDouble(14, 0.0002);
    stmt.setFloat(15, 0.02f);
    stmt.setDouble(16, 0.0002);
    stmt.execute();

    stmt.setString(1, tenantId);
    stmt.setString(2, ROW3);
    stmt.setString(3, A_VALUE);
    stmt.setString(4, E_VALUE);
    stmt.setInt(5, 3);
    stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 2));
    stmt.setBigDecimal(7, null);
    stmt.setNull(8, Types.BIGINT);
    stmt.setNull(9, Types.INTEGER);
    stmt.setNull(10, Types.INTEGER);
    stmt.setByte(11, (byte) 3);
    stmt.setShort(12, (short) 130);
    stmt.setFloat(13, 0.03f);
    stmt.setDouble(14, 0.0003);
    stmt.setFloat(15, 0.03f);
    stmt.setDouble(16, 0.0003);
    stmt.execute();

    stmt.setString(1, tenantId);
    stmt.setString(2, ROW4);
    stmt.setString(3, A_VALUE);
    stmt.setString(4, B_VALUE);
    stmt.setInt(5, 4);
    stmt.setDate(6, date == null ? null : date);
    stmt.setBigDecimal(7, null);
    stmt.setNull(8, Types.BIGINT);
    stmt.setNull(9, Types.INTEGER);
    stmt.setNull(10, Types.INTEGER);
    stmt.setByte(11, (byte) 4);
    stmt.setShort(12, (short) 131);
    stmt.setFloat(13, 0.04f);
    stmt.setDouble(14, 0.0004);
    stmt.setFloat(15, 0.04f);
    stmt.setDouble(16, 0.0004);
    stmt.execute();

    stmt.setString(1, tenantId);
    stmt.setString(2, ROW5);
    stmt.setString(3, B_VALUE);
    stmt.setString(4, C_VALUE);
    stmt.setInt(5, 5);
    stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1));
    stmt.setBigDecimal(7, null);
    stmt.setNull(8, Types.BIGINT);
    stmt.setNull(9, Types.INTEGER);
    stmt.setNull(10, Types.INTEGER);
    stmt.setByte(11, (byte) 5);
    stmt.setShort(12, (short) 132);
    stmt.setFloat(13, 0.05f);
    stmt.setDouble(14, 0.0005);
    stmt.setFloat(15, 0.05f);
    stmt.setDouble(16, 0.0005);
    stmt.execute();

    stmt.setString(1, tenantId);
    stmt.setString(2, ROW6);
    stmt.setString(3, B_VALUE);
    stmt.setString(4, E_VALUE);
    stmt.setInt(5, 6);
    stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 2));
    stmt.setBigDecimal(7, null);
    stmt.setNull(8, Types.BIGINT);
    stmt.setNull(9, Types.INTEGER);
    stmt.setNull(10, Types.INTEGER);
    stmt.setByte(11, (byte) 6);
    stmt.setShort(12, (short) 133);
    stmt.setFloat(13, 0.06f);
    stmt.setDouble(14, 0.0006);
    stmt.setFloat(15, 0.06f);
    stmt.setDouble(16, 0.0006);
    stmt.execute();

    stmt.setString(1, tenantId);
    stmt.setString(2, ROW7);
    stmt.setString(3, B_VALUE);
    stmt.setString(4, B_VALUE);
    stmt.setInt(5, 7);
    stmt.setDate(6, date == null ? null : date);
    stmt.setBigDecimal(7, BigDecimal.valueOf(0.1));
    stmt.setLong(8, 5L);
    stmt.setInt(9, 5);
    stmt.setNull(10, Types.INTEGER);
    stmt.setByte(11, (byte) 7);
    stmt.setShort(12, (short) 134);
    stmt.setFloat(13, 0.07f);
    stmt.setDouble(14, 0.0007);
    stmt.setFloat(15, 0.07f);
    stmt.setDouble(16, 0.0007);
    stmt.execute();

    stmt.setString(1, tenantId);
    stmt.setString(2, ROW8);
    stmt.setString(3, B_VALUE);
    stmt.setString(4, C_VALUE);
    stmt.setInt(5, 8);
    stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1));
    stmt.setBigDecimal(7, BigDecimal.valueOf(3.9));
    long l = Integer.MIN_VALUE - 1L;
    assert (l < Integer.MIN_VALUE);
    stmt.setLong(8, l);
    stmt.setInt(9, 4);
    stmt.setNull(10, Types.INTEGER);
    stmt.setByte(11, (byte) 8);
    stmt.setShort(12, (short) 135);
    stmt.setFloat(13, 0.08f);
    stmt.setDouble(14, 0.0008);
    stmt.setFloat(15, 0.08f);
    stmt.setDouble(16, 0.0008);
    stmt.execute();

    stmt.setString(1, tenantId);
    stmt.setString(2, ROW9);
    stmt.setString(3, C_VALUE);
    stmt.setString(4, E_VALUE);
    stmt.setInt(5, 9);
    stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 2));
    stmt.setBigDecimal(7, BigDecimal.valueOf(3.3));
    l = Integer.MAX_VALUE + 1L;
    assert (l > Integer.MAX_VALUE);
    stmt.setLong(8, l);
    stmt.setInt(9, 3);
    stmt.setInt(10, 300);
    stmt.setByte(11, (byte) 9);
    stmt.setShort(12, (short) 0);
    stmt.setFloat(13, 0.09f);
    stmt.setDouble(14, 0.0009);
    stmt.setFloat(15, 0.09f);
    stmt.setDouble(16, 0.0009);
    stmt.execute();

    stmt.setString(1, tenantId);
    stmt.setString(2, ROW10);
    stmt.setString(3, B_VALUE);
    stmt.setString(4, B_VALUE);
    stmt.setInt(5, 7);
    // Intentionally null
    stmt.setDate(6, null);
    stmt.setBigDecimal(7, BigDecimal.valueOf(0.1));
    stmt.setLong(8, 5L);
    stmt.setInt(9, 5);
    stmt.setNull(10, Types.INTEGER);
    stmt.setByte(11, (byte) 7);
    stmt.setShort(12, (short) 134);
    stmt.setFloat(13, 0.07f);
    stmt.setDouble(14, 0.0007);
    stmt.setFloat(15, 0.07f);
    stmt.setDouble(16, 0.0007);
    stmt.execute();

    conn.commit();
    return tableName;

}

From source file:org.apache.phoenix.end2end.index.IndexExpressionIT.java

/**
 * Adds a row to the index data table//from   w  ww .  ja  va2s.c  o  m
 * 
 * @param i
 *            row number
 */
private void insertRow(PreparedStatement stmt, int i) throws SQLException {
    // insert row
    stmt.setString(1, "varchar" + String.valueOf(i));
    stmt.setString(2, "char" + String.valueOf(i));
    stmt.setInt(3, i);
    stmt.setLong(4, i);
    stmt.setBigDecimal(5, new BigDecimal(i * 0.5d));
    Date date = new Date(DateUtil.parseDate("2015-01-01 00:00:00").getTime() + (i - 1) * NUM_MILLIS_IN_DAY);
    stmt.setDate(6, date);
    stmt.setString(7, "a.varchar" + String.valueOf(i));
    stmt.setString(8, "a.char" + String.valueOf(i));
    stmt.setInt(9, i);
    stmt.setLong(10, i);
    stmt.setBigDecimal(11, new BigDecimal(i * 0.5d));
    stmt.setDate(12, date);
    stmt.setString(13, "b.varchar" + String.valueOf(i));
    stmt.setString(14, "b.char" + String.valueOf(i));
    stmt.setInt(15, i);
    stmt.setLong(16, i);
    stmt.setBigDecimal(17, new BigDecimal(i * 0.5d));
    stmt.setDate(18, date);
    stmt.executeUpdate();
}

From source file:org.apache.phoenix.end2end.index.IndexExpressionIT.java

protected void helpTestUpdate(boolean localIndex) throws Exception {
    String dataTableName = MUTABLE_INDEX_DATA_TABLE;
    String fullDataTableName = INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + dataTableName;
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {/*  w  w  w. j  ava 2 s  . com*/
        conn.setAutoCommit(false);
        populateDataTable(conn, dataTableName);

        // create an expression index
        String ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX IDX ON " + fullDataTableName
                + " ((UPPER(varchar_pk) || '_' || UPPER(char_pk) || '_' || UPPER(varchar_col1) || '_' || UPPER(char_col2)),"
                + " (decimal_pk+int_pk+decimal_col2+int_col1)," + " date_pk+1, date1+1, date2+1 )"
                + " INCLUDE (long_col1, long_col2)";
        PreparedStatement stmt = conn.prepareStatement(ddl);
        stmt.execute();

        // update index pk column and covered column
        String upsert = "UPSERT INTO " + fullDataTableName
                + "(varchar_pk, char_pk, int_pk, long_pk, decimal_pk, date_pk, varchar_col1, long_col1) VALUES(?, ?, ?, ?, ?, ?, ?, ?)";

        stmt = conn.prepareStatement(upsert);
        stmt.setString(1, "varchar1");
        stmt.setString(2, "char1");
        stmt.setInt(3, 1);
        stmt.setLong(4, 1l);
        stmt.setBigDecimal(5, new BigDecimal(0.5));
        stmt.setDate(6, DateUtil.parseDate("2015-01-01 00:00:00"));
        stmt.setString(7, "a.varchar_updated");
        stmt.setLong(8, 101);
        stmt.executeUpdate();
        conn.commit();

        // verify only one row was updated in the data table
        String selectSql = "UPPER(varchar_pk) || '_' || UPPER(char_pk) || '_' || UPPER(varchar_col1) || '_' || UPPER(char_col2), long_col1 from "
                + fullDataTableName;
        ResultSet rs = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */ " + selectSql);
        assertTrue(rs.next());
        assertEquals("VARCHAR1_CHAR1 _A.VARCHAR_UPDATED_B.CHAR1   ", rs.getString(1));
        assertEquals(101, rs.getLong(2));
        assertTrue(rs.next());
        assertEquals("VARCHAR2_CHAR2 _A.VARCHAR2_B.CHAR2   ", rs.getString(1));
        assertEquals(2, rs.getLong(2));
        assertFalse(rs.next());

        // verify that the rows in the index table are also updated
        rs = conn.createStatement().executeQuery("SELECT " + selectSql);
        assertTrue(rs.next());
        assertEquals("VARCHAR1_CHAR1 _A.VARCHAR_UPDATED_B.CHAR1   ", rs.getString(1));
        assertEquals(101, rs.getLong(2));
        assertTrue(rs.next());
        assertEquals("VARCHAR2_CHAR2 _A.VARCHAR2_B.CHAR2   ", rs.getString(1));
        assertEquals(2, rs.getLong(2));
        assertFalse(rs.next());
        conn.createStatement().execute("DROP INDEX IDX ON " + fullDataTableName);
    } finally {
        conn.close();
    }
}

From source file:org.apache.phoenix.end2end.index.IndexExpressionIT.java

public void helpTestAddPKColumnToTable(boolean mutable, boolean local) throws Exception {
    ResultSet rs;//from   w  ww  . j a v a  2s.c o m
    PreparedStatement stmt;

    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {
        conn.setAutoCommit(false);

        // make sure that the tables are empty, but reachable
        conn.createStatement()
                .execute("CREATE TABLE t" + " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)");
        String dataTableQuery = "SELECT * FROM t";
        rs = conn.createStatement().executeQuery(dataTableQuery);
        assertFalse(rs.next());

        String indexName = "IT_" + (mutable ? "M" : "IM") + "_" + (local ? "L" : "H");
        conn.createStatement().execute(
                "CREATE " + (local ? "LOCAL" : "") + " INDEX " + indexName + " ON t (v1 || '_' || v2)");
        String indexTableQuery = "SELECT * FROM " + indexName;
        rs = conn.createStatement().executeQuery(indexTableQuery);
        assertFalse(rs.next());

        // load some data into the table
        stmt = conn.prepareStatement("UPSERT INTO t VALUES(?,?,?)");
        stmt.setString(1, "a");
        stmt.setString(2, "x");
        stmt.setString(3, "1");
        stmt.execute();
        conn.commit();

        assertIndexExists(conn, true);
        conn.createStatement().execute("ALTER TABLE t ADD v3 VARCHAR, k2 DECIMAL PRIMARY KEY");
        rs = conn.getMetaData().getPrimaryKeys("", "", "T");
        assertTrue(rs.next());
        assertEquals("K", rs.getString("COLUMN_NAME"));
        assertEquals(1, rs.getShort("KEY_SEQ"));
        assertTrue(rs.next());
        assertEquals("K2", rs.getString("COLUMN_NAME"));
        assertEquals(2, rs.getShort("KEY_SEQ"));

        rs = conn.getMetaData().getPrimaryKeys("", "", indexName);
        assertTrue(rs.next());
        assertEquals(IndexUtil.INDEX_COLUMN_NAME_SEP + "(V1 || '_' || V2)", rs.getString("COLUMN_NAME"));
        int offset = local ? 1 : 0;
        assertEquals(offset + 1, rs.getShort("KEY_SEQ"));
        assertTrue(rs.next());
        assertEquals(IndexUtil.INDEX_COLUMN_NAME_SEP + "K", rs.getString("COLUMN_NAME"));
        assertEquals(offset + 2, rs.getShort("KEY_SEQ"));
        assertTrue(rs.next());
        assertEquals(IndexUtil.INDEX_COLUMN_NAME_SEP + "K2", rs.getString("COLUMN_NAME"));
        assertEquals(offset + 3, rs.getShort("KEY_SEQ"));

        // verify data table rows
        rs = conn.createStatement().executeQuery(dataTableQuery);
        assertTrue(rs.next());
        assertEquals("a", rs.getString(1));
        assertEquals("x", rs.getString(2));
        assertEquals("1", rs.getString(3));
        assertNull(rs.getBigDecimal(4));
        assertFalse(rs.next());

        // verify index table rows
        rs = conn.createStatement().executeQuery(indexTableQuery);
        assertTrue(rs.next());
        assertEquals("x_1", rs.getString(1));
        assertEquals("a", rs.getString(2));
        assertNull(rs.getBigDecimal(3));
        assertFalse(rs.next());

        // load some data into the table
        stmt = conn.prepareStatement("UPSERT INTO t(K,K2,V1,V2) VALUES(?,?,?,?)");
        stmt.setString(1, "b");
        stmt.setBigDecimal(2, BigDecimal.valueOf(2));
        stmt.setString(3, "y");
        stmt.setString(4, "2");
        stmt.execute();
        conn.commit();

        // verify data table rows
        rs = conn.createStatement().executeQuery(dataTableQuery);
        assertTrue(rs.next());
        assertEquals("a", rs.getString(1));
        assertEquals("x", rs.getString(2));
        assertEquals("1", rs.getString(3));
        assertNull(rs.getString(4));
        assertNull(rs.getBigDecimal(5));
        assertTrue(rs.next());
        assertEquals("b", rs.getString(1));
        assertEquals("y", rs.getString(2));
        assertEquals("2", rs.getString(3));
        assertNull(rs.getString(4));
        assertEquals(BigDecimal.valueOf(2), rs.getBigDecimal(5));
        assertFalse(rs.next());

        // verify index table rows
        rs = conn.createStatement().executeQuery(indexTableQuery);
        assertTrue(rs.next());
        assertEquals("x_1", rs.getString(1));
        assertEquals("a", rs.getString(2));
        assertNull(rs.getBigDecimal(3));
        assertTrue(rs.next());
        assertEquals("y_2", rs.getString(1));
        assertEquals("b", rs.getString(2));
        assertEquals(BigDecimal.valueOf(2), rs.getBigDecimal(3));
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}

From source file:org.apache.phoenix.end2end.index.IndexMaintenanceIT.java

/**
 * Adds a row to the index data table/*from  w w w.  java 2  s  .co  m*/
 * 
 * @param i
 *            row number
 */
private void insertRow(PreparedStatement stmt, int i) throws SQLException {
    // insert row
    stmt.setString(1, "varchar" + String.valueOf(i));
    stmt.setString(2, "char" + String.valueOf(i));
    stmt.setInt(3, i);
    stmt.setLong(4, i);
    stmt.setBigDecimal(5, new BigDecimal(i * 0.5d));
    Date date = new Date(DateUtil.parseDate("2015-01-01 00:00:00").getTime() + (i - 1) * MILLIS_IN_DAY);
    stmt.setDate(6, date);
    stmt.setString(7, "a.varchar" + String.valueOf(i));
    stmt.setString(8, "a.char" + String.valueOf(i));
    stmt.setInt(9, i);
    stmt.setLong(10, i);
    stmt.setBigDecimal(11, new BigDecimal(i * 0.5d));
    stmt.setDate(12, date);
    stmt.setString(13, "b.varchar" + String.valueOf(i));
    stmt.setString(14, "b.char" + String.valueOf(i));
    stmt.setInt(15, i);
    stmt.setLong(16, i);
    stmt.setBigDecimal(17, new BigDecimal(i * 0.5d));
    stmt.setDate(18, date);
    stmt.executeUpdate();
}

From source file:org.apache.phoenix.end2end.index.IndexMaintenanceIT.java

private void helpTestUpdate(String fullDataTableName, String indexName, boolean localIndex) throws Exception {
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {//from  ww w .  ja  va2s .c  o m
        conn.setAutoCommit(false);
        createDataTable(conn, fullDataTableName, "");
        populateDataTable(conn, fullDataTableName);

        // create an expression index
        String ddl = "CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName + " ON "
                + fullDataTableName
                + " ((UPPER(varchar_pk) || '_' || UPPER(char_pk) || '_' || UPPER(varchar_col1) || '_' || UPPER(char_col2)),"
                + " (decimal_pk+int_pk+decimal_col2+int_col1)," + " date_pk+1, date1+1, date2+1 )"
                + " INCLUDE (long_col1, long_col2)";
        PreparedStatement stmt = conn.prepareStatement(ddl);
        stmt.execute();

        // update index pk column and covered column
        String upsert = "UPSERT INTO " + fullDataTableName
                + "(varchar_pk, char_pk, int_pk, long_pk, decimal_pk, date_pk, varchar_col1, long_col1) VALUES(?, ?, ?, ?, ?, ?, ?, ?)";

        stmt = conn.prepareStatement(upsert);
        stmt.setString(1, "varchar1");
        stmt.setString(2, "char1");
        stmt.setInt(3, 1);
        stmt.setLong(4, 1l);
        stmt.setBigDecimal(5, new BigDecimal(0.5));
        stmt.setDate(6, DateUtil.parseDate("2015-01-01 00:00:00"));
        stmt.setString(7, "a.varchar_updated");
        stmt.setLong(8, 101);
        stmt.executeUpdate();
        conn.commit();

        // verify only one row was updated in the data table
        String selectSql = "UPPER(varchar_pk) || '_' || UPPER(char_pk) || '_' || UPPER(varchar_col1) || '_' || UPPER(char_col2), long_col1 from "
                + fullDataTableName;
        ResultSet rs = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */ " + selectSql);
        assertTrue(rs.next());
        assertEquals("VARCHAR1_CHAR1     _A.VARCHAR_UPDATED_B.CHAR1   ", rs.getString(1));
        assertEquals(101, rs.getLong(2));
        assertTrue(rs.next());
        assertEquals("VARCHAR2_CHAR2     _A.VARCHAR2_B.CHAR2   ", rs.getString(1));
        assertEquals(2, rs.getLong(2));
        assertFalse(rs.next());

        // verify that the rows in the index table are also updated
        rs = conn.createStatement().executeQuery("SELECT " + selectSql);
        assertTrue(rs.next());
        assertEquals("VARCHAR1_CHAR1     _A.VARCHAR_UPDATED_B.CHAR1   ", rs.getString(1));
        assertEquals(101, rs.getLong(2));
        assertTrue(rs.next());
        assertEquals("VARCHAR2_CHAR2     _A.VARCHAR2_B.CHAR2   ", rs.getString(1));
        assertEquals(2, rs.getLong(2));
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}

From source file:org.apache.phoenix.query.BaseTest.java

protected static void initATableValues(String tenantId, byte[][] splits, Date date, Long ts, String url)
        throws Exception {
    if (ts == null) {
        ensureTableCreated(url, ATABLE_NAME, splits);
    } else {/*www .  jav  a  2s .  c om*/
        ensureTableCreated(url, ATABLE_NAME, splits, ts - 5);
    }

    Properties props = new Properties();
    if (ts != null) {
        props.setProperty(CURRENT_SCN_ATTRIB, Long.toString(ts - 3));
    }
    Connection conn = DriverManager.getConnection(url, props);
    try {
        // Insert all rows at ts
        PreparedStatement stmt = conn.prepareStatement("upsert into " + "ATABLE(" + "    ORGANIZATION_ID, "
                + "    ENTITY_ID, " + "    A_STRING, " + "    B_STRING, " + "    A_INTEGER, " + "    A_DATE, "
                + "    X_DECIMAL, " + "    X_LONG, " + "    X_INTEGER," + "    Y_INTEGER," + "    A_BYTE,"
                + "    A_SHORT," + "    A_FLOAT," + "    A_DOUBLE," + "    A_UNSIGNED_FLOAT,"
                + "    A_UNSIGNED_DOUBLE)" + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
        stmt.setString(1, tenantId);
        stmt.setString(2, ROW1);
        stmt.setString(3, A_VALUE);
        stmt.setString(4, B_VALUE);
        stmt.setInt(5, 1);
        stmt.setDate(6, date);
        stmt.setBigDecimal(7, null);
        stmt.setNull(8, Types.BIGINT);
        stmt.setNull(9, Types.INTEGER);
        stmt.setNull(10, Types.INTEGER);
        stmt.setByte(11, (byte) 1);
        stmt.setShort(12, (short) 128);
        stmt.setFloat(13, 0.01f);
        stmt.setDouble(14, 0.0001);
        stmt.setFloat(15, 0.01f);
        stmt.setDouble(16, 0.0001);
        stmt.execute();

        stmt.setString(1, tenantId);
        stmt.setString(2, ROW2);
        stmt.setString(3, A_VALUE);
        stmt.setString(4, C_VALUE);
        stmt.setInt(5, 2);
        stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1));
        stmt.setBigDecimal(7, null);
        stmt.setNull(8, Types.BIGINT);
        stmt.setNull(9, Types.INTEGER);
        stmt.setNull(10, Types.INTEGER);
        stmt.setByte(11, (byte) 2);
        stmt.setShort(12, (short) 129);
        stmt.setFloat(13, 0.02f);
        stmt.setDouble(14, 0.0002);
        stmt.setFloat(15, 0.02f);
        stmt.setDouble(16, 0.0002);
        stmt.execute();

        stmt.setString(1, tenantId);
        stmt.setString(2, ROW3);
        stmt.setString(3, A_VALUE);
        stmt.setString(4, E_VALUE);
        stmt.setInt(5, 3);
        stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 2));
        stmt.setBigDecimal(7, null);
        stmt.setNull(8, Types.BIGINT);
        stmt.setNull(9, Types.INTEGER);
        stmt.setNull(10, Types.INTEGER);
        stmt.setByte(11, (byte) 3);
        stmt.setShort(12, (short) 130);
        stmt.setFloat(13, 0.03f);
        stmt.setDouble(14, 0.0003);
        stmt.setFloat(15, 0.03f);
        stmt.setDouble(16, 0.0003);
        stmt.execute();

        stmt.setString(1, tenantId);
        stmt.setString(2, ROW4);
        stmt.setString(3, A_VALUE);
        stmt.setString(4, B_VALUE);
        stmt.setInt(5, 4);
        stmt.setDate(6, date == null ? null : date);
        stmt.setBigDecimal(7, null);
        stmt.setNull(8, Types.BIGINT);
        stmt.setNull(9, Types.INTEGER);
        stmt.setNull(10, Types.INTEGER);
        stmt.setByte(11, (byte) 4);
        stmt.setShort(12, (short) 131);
        stmt.setFloat(13, 0.04f);
        stmt.setDouble(14, 0.0004);
        stmt.setFloat(15, 0.04f);
        stmt.setDouble(16, 0.0004);
        stmt.execute();

        stmt.setString(1, tenantId);
        stmt.setString(2, ROW5);
        stmt.setString(3, B_VALUE);
        stmt.setString(4, C_VALUE);
        stmt.setInt(5, 5);
        stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1));
        stmt.setBigDecimal(7, null);
        stmt.setNull(8, Types.BIGINT);
        stmt.setNull(9, Types.INTEGER);
        stmt.setNull(10, Types.INTEGER);
        stmt.setByte(11, (byte) 5);
        stmt.setShort(12, (short) 132);
        stmt.setFloat(13, 0.05f);
        stmt.setDouble(14, 0.0005);
        stmt.setFloat(15, 0.05f);
        stmt.setDouble(16, 0.0005);
        stmt.execute();

        stmt.setString(1, tenantId);
        stmt.setString(2, ROW6);
        stmt.setString(3, B_VALUE);
        stmt.setString(4, E_VALUE);
        stmt.setInt(5, 6);
        stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 2));
        stmt.setBigDecimal(7, null);
        stmt.setNull(8, Types.BIGINT);
        stmt.setNull(9, Types.INTEGER);
        stmt.setNull(10, Types.INTEGER);
        stmt.setByte(11, (byte) 6);
        stmt.setShort(12, (short) 133);
        stmt.setFloat(13, 0.06f);
        stmt.setDouble(14, 0.0006);
        stmt.setFloat(15, 0.06f);
        stmt.setDouble(16, 0.0006);
        stmt.execute();

        stmt.setString(1, tenantId);
        stmt.setString(2, ROW7);
        stmt.setString(3, B_VALUE);
        stmt.setString(4, B_VALUE);
        stmt.setInt(5, 7);
        stmt.setDate(6, date == null ? null : date);
        stmt.setBigDecimal(7, BigDecimal.valueOf(0.1));
        stmt.setLong(8, 5L);
        stmt.setInt(9, 5);
        stmt.setNull(10, Types.INTEGER);
        stmt.setByte(11, (byte) 7);
        stmt.setShort(12, (short) 134);
        stmt.setFloat(13, 0.07f);
        stmt.setDouble(14, 0.0007);
        stmt.setFloat(15, 0.07f);
        stmt.setDouble(16, 0.0007);
        stmt.execute();

        stmt.setString(1, tenantId);
        stmt.setString(2, ROW8);
        stmt.setString(3, B_VALUE);
        stmt.setString(4, C_VALUE);
        stmt.setInt(5, 8);
        stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1));
        stmt.setBigDecimal(7, BigDecimal.valueOf(3.9));
        long l = Integer.MIN_VALUE - 1L;
        assert (l < Integer.MIN_VALUE);
        stmt.setLong(8, l);
        stmt.setInt(9, 4);
        stmt.setNull(10, Types.INTEGER);
        stmt.setByte(11, (byte) 8);
        stmt.setShort(12, (short) 135);
        stmt.setFloat(13, 0.08f);
        stmt.setDouble(14, 0.0008);
        stmt.setFloat(15, 0.08f);
        stmt.setDouble(16, 0.0008);
        stmt.execute();

        stmt.setString(1, tenantId);
        stmt.setString(2, ROW9);
        stmt.setString(3, C_VALUE);
        stmt.setString(4, E_VALUE);
        stmt.setInt(5, 9);
        stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 2));
        stmt.setBigDecimal(7, BigDecimal.valueOf(3.3));
        l = Integer.MAX_VALUE + 1L;
        assert (l > Integer.MAX_VALUE);
        stmt.setLong(8, l);
        stmt.setInt(9, 3);
        stmt.setInt(10, 300);
        stmt.setByte(11, (byte) 9);
        stmt.setShort(12, (short) 0);
        stmt.setFloat(13, 0.09f);
        stmt.setDouble(14, 0.0009);
        stmt.setFloat(15, 0.09f);
        stmt.setDouble(16, 0.0009);
        stmt.execute();

        conn.commit();
    } finally {
        conn.close();
    }
}

From source file:org.apache.phoenix.query.BaseTest.java

public static void upsertRow(Connection conn, String fullTableName, int index, boolean firstRowInBatch)
        throws SQLException {
    String upsert = "UPSERT INTO " + fullTableName
            + " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    PreparedStatement stmt = conn.prepareStatement(upsert);
    stmt.setString(1, firstRowInBatch ? "firstRowInBatch_" : "" + "varchar" + index);
    stmt.setString(2, "char" + index);
    stmt.setInt(3, index);//from w w  w  . j a v a2s.  c o  m
    stmt.setLong(4, index);
    stmt.setBigDecimal(5, new BigDecimal(index));
    Date date = DateUtil.parseDate("2015-01-01 00:00:00");
    stmt.setDate(6, date);
    stmt.setString(7, "varchar_a");
    stmt.setString(8, "chara");
    stmt.setInt(9, index + 1);
    stmt.setLong(10, index + 1);
    stmt.setBigDecimal(11, new BigDecimal(index + 1));
    stmt.setDate(12, date);
    stmt.setString(13, "varchar_b");
    stmt.setString(14, "charb");
    stmt.setInt(15, index + 2);
    stmt.setLong(16, index + 2);
    stmt.setBigDecimal(17, new BigDecimal(index + 2));
    stmt.setDate(18, date);
    stmt.executeUpdate();
}

From source file:org.apache.phoenix.query.BaseTest.java

protected static void populateMultiCFTestTable(String tableName, Date date) throws SQLException {
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {//from   w  ww .ja va 2 s  . c o m
        String upsert = "UPSERT INTO " + tableName + " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        PreparedStatement stmt = conn.prepareStatement(upsert);
        stmt.setString(1, "varchar1");
        stmt.setString(2, "char1");
        stmt.setInt(3, 1);
        stmt.setLong(4, 1L);
        stmt.setBigDecimal(5, new BigDecimal("1.1"));
        stmt.setString(6, "varchar_a");
        stmt.setString(7, "chara");
        stmt.setInt(8, 2);
        stmt.setLong(9, 2L);
        stmt.setBigDecimal(10, new BigDecimal("2.1"));
        stmt.setString(11, "varchar_b");
        stmt.setString(12, "charb");
        stmt.setInt(13, 3);
        stmt.setLong(14, 3L);
        stmt.setBigDecimal(15, new BigDecimal("3.1"));
        stmt.setDate(16, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY));
        stmt.executeUpdate();

        stmt.setString(1, "varchar2");
        stmt.setString(2, "char2");
        stmt.setInt(3, 2);
        stmt.setLong(4, 2L);
        stmt.setBigDecimal(5, new BigDecimal("2.2"));
        stmt.setString(6, "varchar_a");
        stmt.setString(7, "chara");
        stmt.setInt(8, 3);
        stmt.setLong(9, 3L);
        stmt.setBigDecimal(10, new BigDecimal("3.2"));
        stmt.setString(11, "varchar_b");
        stmt.setString(12, "charb");
        stmt.setInt(13, 4);
        stmt.setLong(14, 4L);
        stmt.setBigDecimal(15, new BigDecimal("4.2"));
        stmt.setDate(16, date);
        stmt.executeUpdate();

        stmt.setString(1, "varchar3");
        stmt.setString(2, "char3");
        stmt.setInt(3, 3);
        stmt.setLong(4, 3L);
        stmt.setBigDecimal(5, new BigDecimal("3.3"));
        stmt.setString(6, "varchar_a");
        stmt.setString(7, "chara");
        stmt.setInt(8, 4);
        stmt.setLong(9, 4L);
        stmt.setBigDecimal(10, new BigDecimal("4.3"));
        stmt.setString(11, "varchar_b");
        stmt.setString(12, "charb");
        stmt.setInt(13, 5);
        stmt.setLong(14, 5L);
        stmt.setBigDecimal(15, new BigDecimal("5.3"));
        stmt.setDate(16, date == null ? null : new Date(date.getTime() + 2 * MILLIS_IN_DAY));
        stmt.executeUpdate();

        conn.commit();
    } finally {
        conn.close();
    }
}

From source file:org.apache.phoenix.util.TestUtil.java

public static void setRowKeyColumns(PreparedStatement stmt, int i) throws SQLException {
    // insert row
    stmt.setString(1, "varchar" + String.valueOf(i));
    stmt.setString(2, "char" + String.valueOf(i));
    stmt.setInt(3, i);//  w  w  w.jav  a  2  s. com
    stmt.setLong(4, i);
    stmt.setBigDecimal(5, new BigDecimal(i * 0.5d));
    Date date = new Date(DateUtil.parseDate("2015-01-01 00:00:00").getTime() + (i - 1) * MILLIS_IN_DAY);
    stmt.setDate(6, date);
}