简体   繁体   中英

Getting java.sql.RowId from Java ResultSet

This is proving to be more difficult than I expected. I am trying to get the Oracle rowid ( java.sql.RowId ) for a row from a ResultSet object.

RowId rowid = rs.getRowId("rowid");

this fails, doesn't like the input String "rowid".

Integer columnIndex = 2;
RowId rowid = rs.getRowId(columnIndex);

this fails because it doesn't like the integer value of the column index.

So which column index do I pass for a metacolumn such as rownum or rowid?

If I were the designers, I would have made rowid have a columnindex of 0, -1, or -2, or -3, or something, but that's me.

It looks like you need to select the rowid as a column in your query, then access the column (by name or index) with the getRowId() method.

For example.

select
        rowid,
        blammy
    from
        tablename
    where
        something = desiredvalue

Then

    RowId rowid = rs.getRowId("rowid");

or

    RowId rowid = rs.getRowId(1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM