Java Code Examples for java.sql.PreparedStatement#setFloat()

The following examples show how to use java.sql.PreparedStatement#setFloat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NumericArithmeticIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testScanByFloatValue() throws Exception {
    String query = "SELECT a_string, b_string, a_float FROM " + tableName + " WHERE ?=organization_id and ?=a_float";
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setString(1, getOrganizationId());
        statement.setFloat(2, 0.01f);
        ResultSet rs = statement.executeQuery();
        assertTrue (rs.next());
        assertEquals(rs.getString(1), A_VALUE);
        assertEquals(rs.getString("B_string"), B_VALUE);
        assertTrue(Floats.compare(rs.getFloat(3), 0.01f) == 0);
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example 2
Source File: NumericArithmeticIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testScanByUnsignedFloatValue() throws Exception {
    String query = "SELECT a_string, b_string, a_unsigned_float FROM " + tableName + " WHERE ?=organization_id and ?=a_unsigned_float";
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {
        PreparedStatement statement = conn.prepareStatement(query);
        statement.setString(1, getOrganizationId());
        statement.setFloat(2, 0.01f);
        ResultSet rs = statement.executeQuery();
        assertTrue (rs.next());
        assertEquals(rs.getString(1), A_VALUE);
        assertEquals(rs.getString("B_string"), B_VALUE);
        assertTrue(Floats.compare(rs.getFloat(3), 0.01f) == 0);
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}
 
Example 3
Source File: AbstractIndexTest.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
private String appendToStatement(PreparedStatement statementToCheck, int[] numbers) throws Exception {
    int nextSpot=1;
    StringBuilder queryString = new StringBuilder();
    if(numbers[0]>=0){
        statementToCheck.setInt(nextSpot,numbers[0]);
        queryString.append("a = ").append(numbers[0]).append(",");
        nextSpot++;
    }
    if(numbers[1]>=0){
        statementToCheck.setFloat(nextSpot,numbers[1]);
        queryString.append("b = ").append(numbers[1]).append(",");
        nextSpot++;
    }
    if(numbers[2]>=0){
        statementToCheck.setInt(nextSpot,numbers[2]);
        queryString.append("c = ").append(numbers[2]).append(",");
        nextSpot++;
    }
    if(numbers[3]>=0){
        statementToCheck.setDouble(nextSpot, numbers[3]);
        queryString.append("d = ").append(numbers[3]).append(",");
    }
    return queryString.toString();
}
 
Example 4
Source File: PreparedStatementAdapterTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 5 votes vote down vote up
@Test
public void assertSetFloat() throws SQLException {
    for (PreparedStatement each : preparedStatements) {
        each.setFloat(1, 0F);
        assertParameter(each, 1, 0F);
    }
}
 
Example 5
Source File: SerialAsyncEventListenerDUnit.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public boolean processEvents(List<Event> events) {
  for (Event e : events) {
    LOG.info("AggregateListener::Processing event" + e);
    if (e.getType() == Event.Type.AFTER_INSERT) {
      ResultSet eventRS = e.getNewRowsAsResultSet();
      try {
        PreparedStatement s = selectStmt.get();
        s.setInt(1, eventRS.getInt("weekday"));
        s.setInt(2, eventRS.getInt("time_slice"));
        s.setInt(3, eventRS.getInt("plug_id"));
        ResultSet queryRS = s.executeQuery();

        if (queryRS.next()) {
          PreparedStatement update = updateStmt.get();
          update.setFloat(1,
              queryRS.getFloat("total_load") + eventRS.getFloat(valueColumn));
          update.setInt(2, queryRS.getInt("event_count") + 1);
          update.setInt(3, queryRS.getInt("weekday"));
          update.setInt(4, queryRS.getInt("time_slice"));
          update.setInt(5, queryRS.getInt("plug_id"));
          update.executeUpdate();
        }
      } catch (SQLException ex) {
        ex.printStackTrace();
      }
    }
  }
  return true;
}
 
Example 6
Source File: LnLogFunctionEnd2EndIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void updateTableSpec(Connection conn, double data, String tableName) throws Exception {
    PreparedStatement stmt =
            conn.prepareStatement("UPSERT INTO " + tableName + " VALUES (?, ?, ?, ?, ?, ?, ?)");
    stmt.setString(1, KEY);
    Double d = Double.valueOf(data);
    stmt.setDouble(2, d.doubleValue());
    stmt.setFloat(3, d.floatValue());
    stmt.setInt(4, d.intValue());
    stmt.setLong(5, d.longValue());
    stmt.setShort(6, d.shortValue());
    stmt.setByte(7, d.byteValue());
    stmt.executeUpdate();
    conn.commit();
}
 
Example 7
Source File: XmlQuerySender.java    From iaf with Apache License 2.0 5 votes vote down vote up
private void applyParameters(PreparedStatement statement, Vector<Column> columns) throws SQLException {
	Iterator<Column> iter = columns.iterator();
	int var = 1;
	while (iter.hasNext()) {
		Column column = iter.next();
		if (column.getParameter() != null) {
			if (column.getParameter() instanceof Integer) {
				log.debug("parm [" + var + "] is an Integer with value [" + column.getParameter().toString() + "]");
				statement.setInt(var, Integer.parseInt(column.getParameter().toString()));
				var++;
			} else if (column.getParameter() instanceof Boolean) {
				log.debug("parm [" + var + "] is an Boolean with value [" + column.getParameter().toString() + "]");
				statement.setBoolean(var, new Boolean(column.getParameter().toString()));
				var++;
			} else if (column.getParameter() instanceof Float) {
				log.debug("parm [" + var + "] is a Float with value [" + column.getParameter().toString() + "]");
				statement.setFloat(var, Float.parseFloat(column.getParameter().toString()));
				var++;
			} else if (column.getParameter() instanceof Timestamp) {
				log.debug("parm [" + var + "] is a Timestamp with value [" + column.getParameter().toString() + "]");
				statement.setTimestamp(var, (Timestamp) column.getParameter());
				var++;
			} else if (column.getParameter() instanceof byte[]) {
				log.debug("parm [" + var + "] is a byte array with value [" + column.getParameter().toString() + "]");
				statement.setBytes(var, (byte[]) column.getParameter());
				var++;
			} else {
				//if (column.getParameter() instanceof String) 
				log.debug("parm [" + var + "] is a String with value [" + column.getParameter().toString() + "]");
				statement.setString(var, (String) column.getParameter());
				var++;
			}
		}
	}
}
 
Example 8
Source File: SqrtFunctionEnd2EndIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void updateUnsignedTable(Connection conn, double data) throws Exception {
    PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + testUnsignedTable + " VALUES (?, ?, ?, ?, ?, ?, ?)");
    stmt.setString(1, KEY);
    Double d = Double.valueOf(data);
    stmt.setDouble(2, d.doubleValue());
    stmt.setFloat(3, d.floatValue());
    stmt.setInt(4, d.intValue());
    stmt.setLong(5, d.longValue());
    stmt.setShort(6, d.shortValue());
    stmt.setByte(7, d.byteValue());
    stmt.executeUpdate();
    conn.commit();
}
 
Example 9
Source File: AsTest.java    From jTDS with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testBigDecimal() throws Throwable {
    String crtab = "create table #testBigDecimal (a decimal(28,10) NULL)";
    dropTable("#testBigDecimal");
    Statement stmt = con.createStatement();
    stmt.executeUpdate(crtab);
    stmt.close();
    PreparedStatement pstmt = con.prepareStatement("insert into #testBigDecimal values (?)");
    pstmt.setObject(1, new BigDecimal("10.200"));
    pstmt.execute();
    // FIXME With Sybase this should probably throw a DataTruncation, not just a plain SQLException
    pstmt.setObject(1, new BigDecimal(10.200));
    pstmt.execute();
    pstmt.setObject(1, null);
    pstmt.execute();
    pstmt.setObject(1, new Integer(20));
    pstmt.execute();
    pstmt.setObject(1, new Double(2.10));
    pstmt.execute();
    pstmt.setObject(1, new BigDecimal(-10.200));
    pstmt.execute();
    pstmt.setObject(1, new Long(200));
    pstmt.execute();
    pstmt.setByte(1, (byte) 1);
    pstmt.execute();
    pstmt.setInt(1, 200);
    pstmt.execute();
    pstmt.setLong(1, 200L);
    pstmt.execute();
    pstmt.setFloat(1, (float) 1.1);
    pstmt.execute();
    pstmt.setDouble(1, 1.1);
    pstmt.execute();
    pstmt.close();
}
 
Example 10
Source File: ExpFunctionEnd2EndIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void updateUnsignedTable(Connection conn, double data) throws Exception {
    PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + unsignedTableName + " VALUES (?, ?, ?, ?, ?, ?, ?)");
    stmt.setString(1, KEY);
    Double d = Double.valueOf(data);
    stmt.setDouble(2, d.doubleValue());
    stmt.setFloat(3, d.floatValue());
    stmt.setInt(4, d.intValue());
    stmt.setLong(5, d.longValue());
    stmt.setShort(6, d.shortValue());
    stmt.setByte(7, d.byteValue());
    stmt.executeUpdate();
    conn.commit();
}
 
Example 11
Source File: PreparedStatement1IT.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
private void bindOneParamSet(PreparedStatement prepst,
                             int id,
                             double colA,
                             float colB,
                             String colC,
                             long colD,
                             short colE) throws SQLException
{
  prepst.setInt(1, id);
  prepst.setDouble(2, colA);
  prepst.setFloat(3, colB);
  prepst.setString(4, colC);
  prepst.setLong(5, colD);
  prepst.setShort(6, colE);
}
 
Example 12
Source File: GemFireXDDataExtractorJUnit.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
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();
  }
}
 
Example 13
Source File: SignFunctionEnd2EndIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void updateSignedTable(Connection conn, double data) throws Exception {
    PreparedStatement stmt = conn.prepareStatement(
        "UPSERT INTO " + signedTableName + " VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
    stmt.setString(1, KEY);
    Double d = Double.valueOf(data);
    stmt.setBigDecimal(2, BigDecimal.valueOf(data));
    stmt.setDouble(3, d.doubleValue());
    stmt.setFloat(4, d.floatValue());
    stmt.setInt(5, d.intValue());
    stmt.setLong(6, d.longValue());
    stmt.setShort(7, d.shortValue());
    stmt.setByte(8, d.byteValue());
    stmt.executeUpdate();
    conn.commit();
}
 
Example 14
Source File: EventErrorFileToDBWriter.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Set the value of a parameter in prepared statement given a string
 * representation as returned by
 */
public static void setParameters(PreparedStatement pstmt, String[] params,
    ArrayList<Integer> paramTypes) throws Exception {
  for (int index = 0; index < params.length; index++) {
    String param = params[index];
    int paramIndex = index + 1;
    int paramType = paramTypes.get(index);
    byte[] bytes;

    if (param == null) {
      pstmt.setNull(paramIndex, paramType);
      continue;
    }
    switch (paramType) {
      case Types.BIGINT:
        final long longVal = Long.parseLong(param);
        pstmt.setLong(paramIndex, longVal);
        break;
      case Types.BIT:
      case Types.BOOLEAN:
        final boolean boolVal;
        if ("1".equals(param)) {
          boolVal = true;
        }
        else if ("0".equals(param)) {
          boolVal = false;
        }
        else {
          boolVal = Boolean.parseBoolean(param);
        }
        pstmt.setBoolean(paramIndex, boolVal);
        break;
      case Types.DATE:
        final java.sql.Date dateVal = java.sql.Date.valueOf(param);
        pstmt.setDate(paramIndex, dateVal);
        break;
      case Types.DECIMAL:
      case Types.NUMERIC:
        final BigDecimal decimalVal = new BigDecimal(param);
        pstmt.setBigDecimal(paramIndex, decimalVal);
        break;
      case Types.DOUBLE:
        final double doubleVal = Double.parseDouble(param);
        pstmt.setDouble(paramIndex, doubleVal);
        break;
      case Types.FLOAT:
      case Types.REAL:
        final float floatVal = Float.parseFloat(param);
        pstmt.setFloat(paramIndex, floatVal);
        break;
      case Types.INTEGER:
      case Types.SMALLINT:
      case Types.TINYINT:
        final int intVal = Integer.parseInt(param);
        pstmt.setInt(paramIndex, intVal);
        break;
      case Types.TIME:
        final java.sql.Time timeVal = java.sql.Time.valueOf(param);
        pstmt.setTime(paramIndex, timeVal);
        break;
      case Types.TIMESTAMP:
        final java.sql.Timestamp timestampVal = java.sql.Timestamp
            .valueOf(param);
        pstmt.setTimestamp(paramIndex, timestampVal);
        break;
      case Types.BINARY:
      case Types.BLOB:
      case Types.LONGVARBINARY:
      case Types.VARBINARY:
        bytes = ClientSharedUtils.fromHexString(param, 0, param.length());
        pstmt.setBytes(paramIndex, bytes);
        break;
      case Types.JAVA_OBJECT:
        bytes = ClientSharedUtils.fromHexString(param, 0, param.length());
        ByteArrayDataInput in = new ByteArrayDataInput();
        in.initialize(bytes, null);
        pstmt.setObject(paramIndex, DataSerializer.readObject(in));
        break;
      default:
        pstmt.setString(paramIndex, param);
        break;
    }
  }
}
 
Example 15
Source File: MySQL5PlayerRegisteredItemsDAO.java    From aion-germany with GNU General Public License v3.0 4 votes vote down vote up
private boolean storeObjects(Connection con, Collection<HouseObject<?>> objects, int playerId, boolean isNew) {

		if (GenericValidator.isBlankOrNull(objects)) {
			return true;
		}

		PreparedStatement stmt = null;
		try {
			stmt = con.prepareStatement(isNew ? INSERT_QUERY : UPDATE_QUERY);

			for (HouseObject<?> obj : objects) {
				if (obj.getExpireTime() > 0) {
					stmt.setInt(1, obj.getExpireTime());
				}
				else {
					stmt.setNull(1, Types.INTEGER);
				}

				if (obj.getColor() == null) {
					stmt.setNull(2, Types.INTEGER);
				}
				else {
					stmt.setInt(2, obj.getColor());
				}

				stmt.setInt(3, obj.getColorExpireEnd());
				stmt.setInt(4, obj.getOwnerUsedCount());
				stmt.setInt(5, obj.getVisitorUsedCount());
				stmt.setFloat(6, obj.getX());
				stmt.setFloat(7, obj.getY());
				stmt.setFloat(8, obj.getZ());
				stmt.setInt(9, obj.getHeading());
				if (obj.getX() > 0 || obj.getY() > 0 || obj.getZ() > 0) {
					stmt.setString(10, obj.getPlaceArea().toString());
				}
				else {
					stmt.setString(10, "NONE");
				}
				stmt.setByte(11, (byte) 0);
				stmt.setInt(12, playerId);
				stmt.setInt(13, obj.getObjectId());
				stmt.setInt(14, obj.getObjectTemplate().getTemplateId());
				stmt.addBatch();
			}

			stmt.executeBatch();
			con.commit();
		}
		catch (Exception e) {
			log.error("Failed to execute house object update batch", e);
			return false;
		}
		finally {
			DatabaseFactory.close(stmt);
		}
		return true;
	}
 
Example 16
Source File: QueryService.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
/**
 * @param preparedState
 * @param param
 * @throws SQLException
 */
private void setParam(PreparedStatement preparedState, int index, PrepareSqlRequest.StateParam param)
        throws SQLException {
    boolean isNull = (null == param.getValue());

    Class<?> clazz;
    try {
        clazz = Class.forName(param.getClassName());
    } catch (ClassNotFoundException e) {
        throw new InternalErrorException(e);
    }

    Rep rep = Rep.of(clazz);

    switch (rep) {
    case PRIMITIVE_CHAR:
    case CHARACTER:
    case STRING:
        preparedState.setString(index, isNull ? null : String.valueOf(param.getValue()));
        break;
    case PRIMITIVE_INT:
    case INTEGER:
        preparedState.setInt(index, isNull ? 0 : Integer.parseInt(param.getValue()));
        break;
    case PRIMITIVE_SHORT:
    case SHORT:
        preparedState.setShort(index, isNull ? 0 : Short.parseShort(param.getValue()));
        break;
    case PRIMITIVE_LONG:
    case LONG:
        preparedState.setLong(index, isNull ? 0 : Long.parseLong(param.getValue()));
        break;
    case PRIMITIVE_FLOAT:
    case FLOAT:
        preparedState.setFloat(index, isNull ? 0 : Float.parseFloat(param.getValue()));
        break;
    case PRIMITIVE_DOUBLE:
    case DOUBLE:
        preparedState.setDouble(index, isNull ? 0 : Double.parseDouble(param.getValue()));
        break;
    case PRIMITIVE_BOOLEAN:
    case BOOLEAN:
        preparedState.setBoolean(index, !isNull && Boolean.parseBoolean(param.getValue()));
        break;
    case PRIMITIVE_BYTE:
    case BYTE:
        preparedState.setByte(index, isNull ? 0 : Byte.parseByte(param.getValue()));
        break;
    case JAVA_UTIL_DATE:
    case JAVA_SQL_DATE:
        preparedState.setDate(index, isNull ? null : java.sql.Date.valueOf(param.getValue()));
        break;
    case JAVA_SQL_TIME:
        preparedState.setTime(index, isNull ? null : Time.valueOf(param.getValue()));
        break;
    case JAVA_SQL_TIMESTAMP:
        preparedState.setTimestamp(index, isNull ? null : Timestamp.valueOf(param.getValue()));
        break;
    default:
        preparedState.setObject(index, isNull ? null : param.getValue());
    }
}
 
Example 17
Source File: FloatTypeHandler.java    From tangyuan2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setNonNullParameter(PreparedStatement ps, int i, Float parameter, JdbcType jdbcType) throws SQLException {
	ps.setFloat(i, parameter);
}
 
Example 18
Source File: SingleTablePredicatesCheckDUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public static void prepareTable(double price, boolean withForeignKeys,
    boolean withIndexes, Connection conn, boolean isOffHeap) throws SQLException {

    TestUtil.jdbcConn = conn;

    createTable(withForeignKeys, isOffHeap);

    if (withIndexes) {
        // these indexes will evaluate 'select distinct' differently in certain conditions.
        // see testGroupBy_2
      TestUtil.jdbcConn.createStatement().execute(
            "create index testtable_country on TESTTABLE(COUNTRY) ");
        
      TestUtil.jdbcConn.createStatement().execute(
            "create index testtable_address on TESTTABLE(ADDRESS) ");
    }

    PreparedStatement ps = TestUtil.jdbcConn.prepareStatement(
        "insert into TESTTABLE values (?,?,?,?,?, ?,?,?,?,?, ?,? ) ");

    for (int i = 1; i <= 13; ++i) {
         ps.setInt(1, i);

         if(i%2 == 0)
           ps.setNull(2, Types.VARCHAR);
         else
           ps.setString(2, "First"+i);

         if(i%2 == 0 && i > 4 )
           ps.setNull(3, Types.VARCHAR);
         else
           ps.setString(3, (i%3==0?"J 604":"J 987"));

         ps.setString(4, (i%5==0?"INDIA": (i%3==0?"US":"ROWLD")));
         ps.setLong  (5, (i*100) );
         ps.setDouble(6, price);
         ps.setInt   (7, (i*10-i));
         ps.setFloat (8, (i*3.45F) );
         ps.setDouble(9, (i+0.98746D) );
         ps.setInt   (10, Integer.MAX_VALUE);
         
         ps.setInt   (11, (i%5)+1);
         ps.setInt   (12, (i%2)+1);
         
         ps.executeUpdate();
    }

    String createFunction="CREATE FUNCTION times " +
                          "(value INTEGER) " +
                          "RETURNS INTEGER "+
                          "LANGUAGE JAVA " +
                          "EXTERNAL NAME 'com.pivotal.gemfirexd.functions.TestFunctions.times' " +
                          "PARAMETER STYLE JAVA " +
                          "NO SQL " +
                          "RETURNS NULL ON NULL INPUT ";

    TestUtil.jdbcConn.createStatement().execute(createFunction);
}
 
Example 19
Source File: PostgresServerSelectIT.java    From sql-layer with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public String generateResult() throws Exception {
    StringBuilder data = new StringBuilder();
    PreparedStatement stmt = getConnection().prepareStatement(sql);
    if (params != null) {
        for (int i = 0; i < params.length; i++) {
            String param = params[i];
            if (param.startsWith("%")) {
                switch (param.charAt(1)) {
                case 'B':
                    stmt.setBoolean(i + 1, Boolean.parseBoolean(param.substring(2)));
                    break;
                case 'b':
                    stmt.setByte(i + 1, Byte.parseByte(param.substring(2)));
                    break;
                case 's':
                    stmt.setShort(i + 1, Short.parseShort(param.substring(2)));
                    break;
                case 'i':
                    stmt.setInt(i + 1, Integer.parseInt(param.substring(2)));
                    break;
                case 'l':
                    stmt.setLong(i + 1, Long.parseLong(param.substring(2)));
                    break;
                case 'f':
                    stmt.setFloat(i + 1, Float.parseFloat(param.substring(2)));
                    break;
                case 'd':
                    stmt.setDouble(i + 1, Double.parseDouble(param.substring(2)));
                    break;
                case 'n':
                    stmt.setBigDecimal(i + 1, new java.math.BigDecimal(param.substring(2)));
                    break;
                case 'D':
                    stmt.setDate(i + 1, java.sql.Date.valueOf(param.substring(2)));
                    break;
                case 't':
                    stmt.setTime(i + 1, java.sql.Time.valueOf(param.substring(2)));
                    break;
                case 'T':
                    stmt.setTimestamp(i + 1, java.sql.Timestamp.valueOf(param.substring(2)));
                    break;
                default:
                    throw new IllegalArgumentException("Unknown type prefix " + param);
                }
            }
            else
                stmt.setString(i + 1, param);
        }
    }
    ResultSet rs;
    try {
        rs = stmt.executeQuery();
        if (executeTwice()) {
            rs.close();
            rs = stmt.executeQuery();
        }
    }
    catch (Exception ex) {
        if (error == null)
            forgetConnection();
        throw ex;
    }
    ResultSetMetaData md = rs.getMetaData();
    for (int i = 1; i <= md.getColumnCount(); i++) {
        if (i > 1) data.append('\t');
        data.append(md.getColumnLabel(i));
    }
    data.append('\n');
    while (rs.next()) {
        for (int i = 1; i <= md.getColumnCount(); i++) {
            if (i > 1) data.append('\t');
            data.append(rs.getString(i));
        }
        data.append('\n');
    }
    stmt.close();
    return data.toString();
}
 
Example 20
Source File: SQLReal.java    From spliceengine with GNU Affero General Public License v3.0 3 votes vote down vote up
/**
	Set the value into a PreparedStatement.

	@exception SQLException Error setting value in PreparedStatement
*/
public final void setInto(PreparedStatement ps, int position) throws SQLException {

	if (isNull()) {
		ps.setNull(position, java.sql.Types.REAL);
		return;
	}

	ps.setFloat(position, value);
}