value = rs.getString(index); } else if (boolean.class.equals(requiredType) || Boolean.class.equals(requiredType)) { value = Boolean.valueOf(rs.getBoolean(index)); wasNullCheck = true; } else if (float.class.equals(requiredType) || Float.class.equals(requiredType)) { value = new Float(rs.getFloat(index)); wasNullCheck = true; } else if (double.class.equals(requiredType) || Double.class.equals(requiredType) || Number.class.equals(requiredType)) { value = new Double(rs.getDouble(index)); wasNullCheck = true; } else if (Time.class.equals(requiredType)) { value = rs.getString(index);// 尝试拿为string对象,0000无法用Time表示 value = rs.getString(index);
@Test public void testScanByUnsignedFloatValue() throws Exception { String query = "SELECT a_string, b_string, a_unsigned_float FROM aTable WHERE ?=organization_id and ?=a_unsigned_float"; Properties props = new Properties(TEST_PROPERTIES); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2 Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props); try { PreparedStatement statement = conn.prepareStatement(query); statement.setString(1, tenantId); 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(); } }
public void processRow(ResultSet rs) throws SQLException { Key key = new Key(rs.getString("experimentId"), new Trace(rs.getString("traceId")), rs.getInt("stage")); RetrievalCounts cnt = new RetrievalCounts(rs.getInt("relevant_retrieved"), rs.getInt("retrieved"), rs.getInt("relevant"), rs.getFloat("avep"), rs.getInt("binary_relevant"), rs.getInt("count")); counts.put(key, cnt); } };
private void setPrimitive(ResultSet rs, int index, Object bean, Property property, Class<?> type) throws SQLException { if (type == int.class) { property.set(bean, rs.getInt(index)); } else if (type == boolean.class) { property.set(bean, rs.getBoolean(index)); } else if (type == long.class) { property.set(bean, rs.getLong(index)); } else if (type == double.class) { property.set(bean, rs.getDouble(index)); } else if (type == float.class) { property.set(bean, rs.getFloat(index)); } else if (type == short.class) { property.set(bean, rs.getShort(index)); } else if (type == byte.class) { property.set(bean, rs.getByte(index)); } else if (type == char.class) { property.set(bean, rs.getObject(index, type)); } else { throw new RuntimeException("Not primitive type: " + type); } }
while(rs.next()) { assertTrue((byte)1 == (rs.getByte(1)) || (byte)2 == (rs.getByte(1)) || (byte)3 == (rs.getByte(1))); assertTrue((short)128 == (rs.getShort(2)) || (short)129 == (rs.getShort(2)) || (short)130 == (rs.getShort(2))); assertTrue(0.01f == (rs.getFloat(3)) || 0.02f == (rs.getFloat(3)) || 0.03f == (rs.getFloat(3))); assertTrue(0.0001 == (rs.getDouble(4)) || 0.0002 == (rs.getDouble(4)) || 0.0003 == (rs.getDouble(4))); count++; if(count == 3) break;
@Test public void testScanByFloatValue() throws Exception { String query = "SELECT a_string, b_string, a_float FROM aTable WHERE ?=organization_id and ?=a_float"; Properties props = new Properties(TEST_PROPERTIES); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2 Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props); try { PreparedStatement statement = conn.prepareStatement(query); statement.setString(1, tenantId); 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(); } }
public <T extends PrimitiveObject> void testPrimitives(SourceMapper<ResultSet, T> mapper) throws SQLException, Exception { ResultSet rs = mock(ResultSet.class); when(rs.getBoolean(1)).thenReturn(true); when(rs.getByte(2)).thenReturn((byte)0xa3); when(rs.getInt(3)).thenReturn(0xa4); when(rs.getShort(4)).thenReturn((short)0xa5); when(rs.getInt(5)).thenReturn(0xa6); when(rs.getLong(6)).thenReturn(0xffa4l); when(rs.getFloat(7)).thenReturn(3.14f); when(rs.getDouble(8)).thenReturn(3.14159); T object = mapper.map(rs, null); assertEquals(true, object.ispBoolean()); assertEquals((byte)0xa3, object.getpByte()); assertEquals((char)0xa4, object.getpCharacter()); assertEquals((short)0xa5, object.getpShort()); assertEquals((int)0xa6, object.getpInt()); assertEquals((long)0xffa4l, object.getpLong()); assertEquals((float)3.14f, object.getpFloat(), 0); assertEquals((double)3.14159, object.getpDouble(), 0); }
@NoWarning("OBL") void f(Connection con, Integer key) throws SQLException { StringBuffer sql = new StringBuffer("SELECT * FROM xxx WHERE xxx_id = ?"); PreparedStatement ps = con.prepareStatement(sql.toString()); try { ps.setInt(1, key.intValue()); ResultSet rs = ps.executeQuery(); try { rs.next(); int index = 1; Integer firstQuestionId = new Integer(rs.getInt(index++)); String description = rs.getString(index++); Float approvalScore = new Float(rs.getFloat(index++)); } finally { rs.close(); } } finally { ps.close(); } } }
@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(); } }
public void testPrimitivesWithNullValues( SourceMapper<ResultSet, DbBoxedPrimitiveObject> mapper) throws SQLException, Exception { ResultSet rs = mock(ResultSet.class); when(rs.wasNull()).thenReturn(true); when(rs.getBoolean(1)).thenReturn(false); when(rs.getByte(2)).thenReturn((byte)0); when(rs.getInt(3)).thenReturn(0); when(rs.getShort(4)).thenReturn((short)0); when(rs.getInt(5)).thenReturn(0); when(rs.getLong(6)).thenReturn(0l); when(rs.getFloat(7)).thenReturn(0f); when(rs.getDouble(8)).thenReturn(0d); DbBoxedPrimitiveObject object = mapper.map(rs, null); assertNull(object.getoBoolean()); assertNull(object.getoByte()); assertNull(object.getoCharacter()); assertNull(object.getoShort()); assertNull(object.getoInt()); assertNull(object.getoLong()); assertNull(object.getoFloat()); assertNull(object.getoDouble()); } }
result = resultSet.getShort(columnIndex); } else if (int.class == type) { result = resultSet.getInt(columnIndex); } else if (long.class == type) { result = resultSet.getLong(columnIndex); } else if (float.class == type) { result = resultSet.getFloat(columnIndex); } else if (double.class == type) { result = resultSet.getDouble(columnIndex); } else if (String.class == type) { result = resultSet.getString(columnIndex); } else if (BigDecimal.class == type) { result = resultSet.getBigDecimal(columnIndex);