下面列出了java.sql.ResultSet#updateFloat ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Tests calling updateFloat on all columns of the row.
* @exception SQLException database access error. Causes test to
* fail with an error.
*/
public void testUpdateFloat()
throws SQLException
{
Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = s.executeQuery(SELECT_STMT);
rs.next();
for (int i = 1; i <= COLUMNS; i++) {
rs.updateFloat(i, 2.0f);
assertEquals("Expected rs.getFloat(" + i +
") to match updated value", 2, (int) rs.getFloat(i));
}
rs.updateRow();
rs.close();
checkColumnsAreUpdated();
s.close();
}
/**
* Tests calling updateFloat on all columns of the row.
* @exception SQLException database access error. Causes test to
* fail with an error.
*/
public void testUpdateFloat()
throws SQLException
{
Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = s.executeQuery(SELECT_STMT);
rs.next();
for (int i = 1; i <= COLUMNS; i++) {
rs.updateFloat(i, 2.0f);
assertEquals("Expected rs.getFloat(" + i +
") to match updated value", 2, (int) rs.getFloat(i));
}
rs.updateRow();
rs.close();
checkColumnsAreUpdated();
s.close();
}
/**
* Tests calling updateFloat on all columns of the row.
* @exception SQLException database access error. Causes test to
* fail with an error.
*/
public void testUpdateFloat()
throws SQLException
{
Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = s.executeQuery(SELECT_STMT);
rs.next();
for (int i = 1; i <= COLUMNS; i++) {
rs.updateFloat(i, 2.0f);
assertEquals("Expected rs.getFloat(" + i +
") to match updated value", 2, (int) rs.getFloat(i));
}
rs.updateRow();
rs.close();
checkColumnsAreUpdated();
s.close();
}
private static void updateResultSetParam(final GraphReadMethods rg, final ResultSet rs, final String label, final Attribute attr, final int id) throws SQLException {
switch (attr.getAttributeType()) {
case "boolean":
rs.updateBoolean(label, rg.getBooleanValue(attr.getId(), id));
break;
case "date":
final long date = rg.getLongValue(attr.getId(), id);
if (date != Long.MIN_VALUE) {
rs.updateDate(label, new Date(date));
}
break;
case "datetime":
final long timestamp = rg.getLongValue(attr.getId(), id);
if (timestamp != Long.MIN_VALUE) {
rs.updateTimestamp(label, new Timestamp(timestamp));
}
break;
case "integer":
rs.updateInt(label, rg.getIntValue(attr.getId(), id));
break;
case "float":
rs.updateFloat(label, rg.getFloatValue(attr.getId(), id));
break;
case "time":
final long time = rg.getLongValue(attr.getId(), id);
if (time != Long.MIN_VALUE) {
rs.updateTime(label, new Time(time));
}
break;
default:
final String s = rg.getStringValue(attr.getId(), id);
if (s != null) {
rs.updateString(label, s);
}
break;
}
}
private void assertUpdateState(
ResultSet rs,
String colName,
long value,
double dvalue,
int updateType,
String expected) throws SQLException {
try {
switch (updateType) {
case XXX_BYTE:
rs.updateByte(colName, (byte)value);
break;
case XXX_SHORT:
rs.updateShort(colName, (short)value);
case XXX_INT:
rs.updateInt(colName, (int)value);
break;
case XXX_LONG:
rs.updateLong(colName, value);
break;
case XXX_FLOAT:
rs.updateFloat(colName, (float)dvalue);
break;
case XXX_DOUBLE:
rs.updateDouble(colName, dvalue);
break;
default:
fail("wrong argument");
}
fail("exception expected");
} catch (SQLException e) {
println(e.toString());
assertSQLState(expected, e);
}
}
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateFloatForColumnIndex() throws SQLException {
for (ResultSet each : resultSets) {
each.updateFloat(1, 1F);
}
}
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateFloatForColumnLabel() throws SQLException {
for (ResultSet each : resultSets) {
each.updateFloat("label", 1F);
}
}
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateFloatForColumnIndex() throws SQLException {
for (ResultSet each : resultSets) {
each.updateFloat(1, 1F);
}
}
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateFloatForColumnLabel() throws SQLException {
for (ResultSet each : resultSets) {
each.updateFloat("label", 1F);
}
}
/**
Set this value into a ResultSet for a subsequent ResultSet.insertRow
or ResultSet.updateRow. This method will only be called for non-null values.
@exception SQLException thrown by the ResultSet object
@exception StandardException thrown by me accessing my value.
*/
public final void setInto(ResultSet rs, int position) throws SQLException, StandardException {
rs.updateFloat(position, value);
}
/**
Set this value into a ResultSet for a subsequent ResultSet.insertRow
or ResultSet.updateRow. This method will only be called for non-null values.
@exception SQLException thrown by the ResultSet object
@exception StandardException thrown by me accessing my value.
*/
public final void setInto(ResultSet rs, int position) throws SQLException, StandardException {
rs.updateFloat(position, value);
}
/**
Set this value into a ResultSet for a subsequent ResultSet.insertRow
or ResultSet.updateRow. This method will only be called for non-null values.
@exception SQLException thrown by the ResultSet object
@exception StandardException thrown by me accessing my value.
*/
public final void setInto(ResultSet rs, int position) throws SQLException, StandardException {
rs.updateFloat(position, value);
}