Thread: record lock
View Single Post

   
  #2 (permalink)  
Old 02-26-2008, 05:02 PM
Fan Ruo Xin
 
Posts: n/a
Default Re: record lock

This is designed by this way.
If you don't want to release the cusor. You can upgrade the isolation level
to RS, like what you did before.

"xixi" <dai_xi@yahoo.com> wrote in message
news:c0f33a17.0402091631.405b2ebf@posting.google.c om...
> hi, we are using db2 udb v8.1 for win 64bit with fix pack 3, type 4
> driver.
>
> The program below is trying to create a scrollable resultset, then
> when the cursor is moving, the current reading row supposed to be
> locked and not allow other session to update, but can read. so i
> create index on the table on column id, which is unique. The problem
> is when i try to lock the cursor and then there is another statement
> execute and if there is no record found, then i will close this
> cursor, but at the same time, it release the record lock which is
> locked by another cursor. These are two different resultsets, why one
> resultset close will cause this problem? i don't want to have the lock
> release. please help.
>
> Class.forName(jdbcDriver);
> conn = DriverManager.getConnection(catalogUrl, username,
> password);
>
> statement = conn.createStatement(
> ResultSet.TYPE_SCROLL_INSENSITIVE,
> ResultSet.CONCUR_READ_ONLY);
>
> sqlStr = "select id, imno08, imcd90, arno15 from NJIPD.IMLMLNB1
> WHERE imno08='3M' ORDER BY imno08 ASC, imcd90 ASC"; // This is to
> create a scrollable resultset
>
> resultSet = statement.executeQuery(sqlStr);
>
> resultSet.next();
>
>
> if (openForUpdate && !readOnly)
> {
> stm =
> conn.createStatement(
> ResultSet.TYPE_FORWARD_ONLY,
> ResultSet.CONCUR_UPDATABLE);
>
> sqlStr = "select id, imno08, imcd90, arno15,from NJIPD.IMLMLNB1
> WHERE id=42"; // this is try to create a row lock
>
> tmpCursor = stm.executeQuery(sqlStr);
>
> tmpCursor.next(); // I do get a row U lock
>
> sqlStr = "select id, imno08, apno01, prno02 from NJIPD.IMPWSBS
> WHERE imno08='3M' ORDER BY imno08 ASC, apno01 ASC, prno02 ASC"; //
> This is another table and there is no resultset returned
>
> Statement stmt = conn.createStatement(
> ResultSet.TYPE_SCROLL_INSENSITIVE,
> ResultSet.CONCUR_READ_ONLY);
>
> cursor = stmt.executeQuery(sqlStr); // The row U lock still there
> if (!cursor.isBeforeFirst())
> cursor.close(); // The row U lock is released, why?



Reply With Quote