下面列出了java.sql.ResultSet#updateLong ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void markFailed(Connection connection, Collection<Tuple2<String, String>> failedSnapshotDefinitions)
throws Exception
{
ResultSet resultSet = connection.createStatement(
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE).executeQuery(SD_SELECT_ALL);
while (resultSet.next())
{
String rscName = resultSet.getString(SD_RES_NAME);
String snapshotName = resultSet.getString(SD_NAME);
if (failedSnapshotDefinitions.contains(Tuples.of(rscName, snapshotName)))
{
resultSet.updateLong(SD_FLAGS,
(resultSet.getLong(SD_FLAGS) & ~SD_FLAG_SUCCESSFUL) | SD_FLAG_FAILED_DEPLOYMENT
);
resultSet.updateRow();
}
}
resultSet.close();
}
/**
* Tests calling updateLong on all columns of the row.
* @exception SQLException database access error. Causes test to
* fail with an error.
*/
public void testUpdateLong()
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.updateLong(i, 2L);
assertEquals("Expected rs.getLong(" + i +
") to match updated value", 2L, rs.getLong(i));
}
rs.updateRow();
rs.close();
checkColumnsAreUpdated();
s.close();
}
/**
* Tests calling updateLong on all columns of the row.
* @exception SQLException database access error. Causes test to
* fail with an error.
*/
public void testUpdateLong()
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.updateLong(i, 2L);
assertEquals("Expected rs.getLong(" + i +
") to match updated value", 2L, rs.getLong(i));
}
rs.updateRow();
rs.close();
checkColumnsAreUpdated();
s.close();
}
/**
* Tests calling updateLong on all columns of the row.
* @exception SQLException database access error. Causes test to
* fail with an error.
*/
public void testUpdateLong()
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.updateLong(i, 2L);
assertEquals("Expected rs.getLong(" + i +
") to match updated value", 2L, rs.getLong(i));
}
rs.updateRow();
rs.close();
checkColumnsAreUpdated();
s.close();
}
/**
* Calls updateLong on the given ResultSet with the given value
* for the position of this PlaceHolder.
*/
public void updateLong(long value, ResultSet rs)
throws SQLException
{
if(isInQuery()) {
rs.updateLong(getIndex(), value);
}
}
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 assertUpdateLongForColumnIndex() throws SQLException {
for (ResultSet each : resultSets) {
each.updateLong(1, 1L);
}
}
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateLongForColumnLabel() throws SQLException {
for (ResultSet each : resultSets) {
each.updateLong("label", 1L);
}
}
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateLongForColumnIndex() throws SQLException {
for (ResultSet each : resultSets) {
each.updateLong(1, 1L);
}
}
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertUpdateLongForColumnLabel() throws SQLException {
for (ResultSet each : resultSets) {
each.updateLong("label", 1L);
}
}
private void updateClob2(String testId,
PreparedStatement sel,
int cloblen, int id, int updateRowId, int updateIdVal, String file)
throws Exception {
println("========================================");
println("START " + testId
+ " - select and then update clob of size= "
+ cloblen + " - Uses updateClob api");
PreparedStatement ps1 =
prepareStatement("SELECT * FROM CLOBTBL FOR UPDATE",
ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE);
PreparedStatement ps =
prepareStatement("SELECT CONTENT,DLEN FROM CLOBTBL2 " +
"where ID =?");
ps.setInt(1, id);
// retrieve row from clobtbl2
ResultSet rs = ps.executeQuery();
rs.next();
Clob value = rs.getClob(1);
long l = value.length();
long dlen = rs.getLong(2);
if (dlen != l) {
println("FAIL - MISMATCH LENGTHS GOT " + l + " expected "
+ dlen + " for row in CLOBTBL2 with ID=" + id);
}
ResultSet rs1 = ps1.executeQuery();
while (rs1.next()) {
if (rs1.getInt(1) == updateRowId) {
rs1.updateClob(4, value);
rs1.updateInt(1, updateIdVal);
rs1.updateInt(2, 0);
rs1.updateLong(3, dlen);
rs1.updateRow();
break;
}
}
commit();
// close resultsets
rs.close();
rs1.close();
// verify
// now select and verify that update went through ok.
sel.setInt(1, updateIdVal);
ResultSet rs2 = sel.executeQuery();
rs2.next();
Clob updatedValue = rs2.getClob(1);
assertEquals("FAIL - MISMATCH length of updated clob value ," +
"found=" +
updatedValue.length() + ",expected = " + l,
l, updatedValue.length());
compareClobToFile(updatedValue.getCharacterStream(), file, (int) l);
if (updatedValue.length() != l) {
println("FAIL - MISMATCH length of updated clob value ," +
"found="
+
updatedValue.length() + ",expected = " + l);
} else
compareClobToFile(updatedValue.getCharacterStream(), file, (int) l);
println("========================================");
}
/**
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
*/
public final void setInto(ResultSet rs, int position) throws SQLException {
rs.updateLong(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
*/
public final void setInto(ResultSet rs, int position) throws SQLException {
rs.updateLong(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
*/
public final void setInto(ResultSet rs, int position) throws SQLException {
rs.updateLong(position, value);
}