2012-03-27 3 views
0

oracle jdbc cachedrowset 구현을 사용하여 쿼리에서 반환되는 여러 행을 선택합니다. 그런 다음 cachedrowset.updateInt() 또는 다른 업데이트 메소드를 사용하여 일부 데이터를 업데이트합니다. 나는 처음에 cachedrowset.beforeFirst()를 사용하여 커서를 다시 얻은 다음 다시 행 집합을 탐색하여 데이터를 인쇄합니다.OracleCachedRowSet 데이터베이스에 쓰지 않고 메모리의 데이터를 업데이트합니다.

데이터가 원래 getInt()를 사용하여 얻은 데이터입니다. 다시 원래 데이터로 바뀝니다. 원래 데이터로 대체되는 데이터를 가져오고 싶습니다. 나는 db에 변경을가하도록 의도하지 않았습니다.

나는 데이터 조작 및 뷰에 대해서만 DB의 데이터를 변경하지 않고 Rowset 개체를 데이터 래퍼로 사용할 수 있다고 생각했습니다. 원래 날짜 대신 업데이트 된 날짜를 얻을 수있는 방법이 있습니까? 난 내 자신의

편집의 데이터 래퍼 객체를 코딩하고 싶지 않았다

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; 
    } 
} 

답변

0

같은 함수 정의는 메모리에 기록 변경하려면 적절한 업데이트 방법 (updateInt()에 updateString() 등) 사용 후() 볼 것이다. 이 upateRow()의 JavaDoc에서 "이 ResultSet 객체의 현재 행에 대한 새로운 내용으로 기본 데이터베이스를 업데이트합니다."

그런 경우에만 발생합니다. updateRow()는 기본 db가 아니라 메모리의 데이터를 업데이트합니다. http://www.scribd.com/doc/68052701/8/Setting-Up-a-CachedRowSet-Object

그래서 내가 단순히 데이터를 업데이트 한 후에 updateRow를 호출했다 않았다 : 나는 링크에서 문서 솔루션에서 발견

while (cachedRowSet.next()) { 
     for (int i = 0; i < columnCount; i++) { 

       dataHandler.updateRowSetData(cachedRowSet, i + 1, columnTypes[i], getUpdatedData()); 
       cachedRowSet.updateRow(); //Adding this line solves the problem. Otherwise changes are not made 

     } 
    } 
0
:이

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); 
    } 
} 

업데이트 코드 나 데이터를 얻을 방법이며, 아래 내가 그것을 업데이트하는 방법입니다

다음과 같이 OracleCachedRowSet의 읽기 전용 설정을 변경하십시오.

oracleCachedRowSet.setReadOnly(false); 

이 방법은 행 집합 클래스가 구현하는 javax.sql.RowSet에 정의되어 있습니다.

편집 : 당신이 게시 코드,

을 바탕으로 당신은 당신이 값을 기준으로 패스를하고 있다는 것을 관찰에 맞다. 사실, 자바에서 항상 값으로 전달하고 참조로 전달하지 마십시오.

해결 방법 : 현재 함수가 무효 반환

이 업데이트 된 cachedRowSet를 반환하도록 변경합니다. 이 솔루션은 cachedRowSet.updateRow를 호출하는 것입니다

public CachedRowSet updateRowSetData(CachedRowSet cachedRowSet, int columnIndex, int columnType, Object data) 
     throws SQLException 
+0

가 나는 것을 시도를하지만, 불행히도 게시 할 수 – Bren

+0

를 작동하지 않았다 당신이 작업하고있는 몇 가지 샘플 코드? – Santosh

+0

물론, 내 질문에 따라 editted @ Santosh – Bren

관련 문제