JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » JDBC/SQL討論區 » Microsoft SQL Server  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 關於select for update的問題
honienglon





發文: 59
積分: 0
於 2011-02-07 16:32 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
如果要用select * with (rowlock) from myTable where id=1 for update.
是否一定要用SelectMethod=cursor ?


reply to postreply to post
作者 Re:關於select for update的問題 [Re:honienglon]
koji

秒速5センチメートル

站長

發文: 8415
積分: 19
於 2011-02-07 18:19 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你可以先試試看

koji


reply to postreply to post
JCConf Taiwan 2015 開始售票了!!
Facebook上的TWJUG社團,歡迎加入
作者 Re:關於select for update的問題 [Re:koji]
honienglon





發文: 59
積分: 0
於 2011-02-08 09:05 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
koji wrote:
你可以先試試看

koji


不行, 出了exception

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
--- Cause: com.microsoft.sqlserver.jdbc.SQLServerException: Line 1: FOR UPDATE clause allowed only for DECLARE CURSOR.
  at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:201)
  at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForObject(MappedStatement.java:120)
  at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:518)
  at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:493)
  at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106)
  at org.springframework.orm.ibatis.SqlMapClientTemplate$1.doInSqlMapClient(SqlMapClientTemplate.java:273)
  at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:209)
  ... 48 more
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Line 1: FOR UPDATE clause allowed only for DECLARE CURSOR.
  at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)
  at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(Unknown Source)
  at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(Unknown Source)
  at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(Unknown Source)
  at com.microsoft.sqlserver.jdbc.TDSCommand.execute(Unknown Source)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(Unknown Source)
  at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(Unknown Source)
  at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(Unknown Source)
  at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(Unknown Source)
  at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:169)
  at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:185)
  at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteQuery(MappedStatement.java:221)
  at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:189)
  ... 54 more


我不想用selectMethod=cursor, 因為DB的效能會變慢


reply to postreply to post
作者 Re:關於select for update的問題 [Re:honienglon]
kenshin520





發文: 109
積分: 0
於 2011-02-23 14:41 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
看來你是用SQLServer。
我之前也是有類似的問題。
你想做的是當你select這比資料後就要把他lock住不讓別人來read/write對吧?
如果是對話用with(updlock) (還是updatelock我忘了完整的lock名了)
只要你有控制在同一個transaction裡,在你這個transaction結束之前那筆資料會被update lock鎖住,只有你可以再update他。


reply to postreply to post
» JWorld@TW »  JDBC/SQL討論區 » Microsoft SQL Server

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8