我正在使用oracle jdbc cachedrowset实现来选择从查询返回的几行。然后我使用cachedrowset.updateInt()或其他更新方法更新一些数据。我首先使用cachedrowset.beforeFirst()返回光标,然后再次遍历行集以打印数据。OracleCachedRowSet更新内存中的数据而不写入数据库
事情是我使用getInt()的数据再次是原始数据。我想获取用原始数据取代的数据。我不打算提交对数据库的更改。
我以为我可以使用Rowset对象作为数据包装,而无需更改数据库上的任何数据,仅用于数据操作和查看。有什么办法可以得到更新的日期而不是原来的日期?我不想代码我自己
编辑的数据包装对象:这是我得到的数据,以下是我如何更新
public OracleCachedRowSet getCachedRowset(String query, Connection con)
throws DTSException {
try {
OracleCachedRowSet cachedRowSet = new OracleCachedRowSet();
cachedRowSet.setReadOnly(false);
cachedRowSet.setCommand(query);
cachedRowSet.execute(con);
return cachedRowSet;
} catch (SQLException sqle) {
throw new DTSException("Error fetching data! :" + sqle.getMessage(), sqle);
}
}
更新代码:
public void updateRowSetData(CachedRowSet cachedRowSet, int columnIndex, int columnType, Object data)
throws SQLException {
switch (columnType) {
case Types.NUMERIC:
case Types.DECIMAL:
cachedRowSet.updateBigDecimal(columnIndex, (BigDecimal) data);
return;
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGNVARCHAR:
cachedRowSet.updateString(columnIndex, data == null ? null : data.toString());
return;
case Types.INTEGER:
cachedRowSet.updateInt(columnIndex, (Integer) data);
return;
case Types.DATE:
cachedRowSet.updateDate(columnIndex, (Date) data);
return;
case Types.TIMESTAMP:
cachedRowSet.updateTimestamp(columnIndex, (Timestamp) data);
return;
case Types.TIME:
cachedRowSet.updateTime(columnIndex, (Time) data);
return;
case Types.BIGINT:
cachedRowSet.updateLong(columnIndex, data == null ? null : Long.parseLong(data.toString()));
return;
case Types.DOUBLE:
case Types.FLOAT:
cachedRowSet.updateDouble(columnIndex, (Double) data);
return;
case Types.SMALLINT:
cachedRowSet.updateShort(columnIndex, data == null ? null : Short.parseShort(data.toString()));
return;
case Types.TINYINT:
cachedRowSet.updateByte(columnIndex, Byte.parseByte(data == null ? null : data.toString()));
return;
case Types.BINARY:
case Types.VARBINARY:
cachedRowSet.updateBytes(columnIndex, (byte[]) data);
return;
case Types.CLOB:
if (data != null) {
cachedRowSet.updateClob(columnIndex, ((Clob) data).getCharacterStream());
} else {
cachedRowSet.updateClob(columnIndex, (Clob) data);
}
return;
case Types.ARRAY:
cachedRowSet.updateArray(columnIndex, (Array) data);
return;
case Types.BLOB:
if (data != null) {
cachedRowSet.updateBlob(columnIndex, data == null ? null : ((Blob) data).getBinaryStream());
} else {
cachedRowSet.updateBlob(columnIndex, (Blob) data);
}
return;
case Types.REAL:
cachedRowSet.updateFloat(columnIndex, (Float) data);
return;
case Types.BIT:
case Types.BOOLEAN:
cachedRowSet.updateBoolean(columnIndex, (Boolean) data);
return;
case Types.REF:
cachedRowSet.updateRef(columnIndex, (Ref) data);
return;
case Types.LONGVARBINARY:
cachedRowSet.updateBinaryStream(columnIndex, (InputStream) data);
return;
default:
cachedRowSet.updateObject(columnIndex, data);
return;
}
}
我试过了,但遗憾的是它没有工作 – Bren 2012-03-27 10:37:26
可以发布你正在处理的一些示例代码? – Santosh 2012-03-27 11:08:39
当然,相应地编辑我的问题@Santosh – Bren 2012-03-27 11:27:47