【问题标题】:Select content from repository where id = ? for update从 id = 的存储库中选择内容?更新
【发布时间】:2012-12-05 06:35:13
【问题描述】:

以上查询在 Oracle 10g 上成功运行。现在我必须使用 SQLSERVER 2005 实现相同的查询(应用程序)。

当我在 SQLSERVER 2005 中运行上述查询时,我收到错误“FOR UPDATE 子句仅允许用于 DECLARE CURSOR”。

SQLSERVER 2005 是否支持上述查询?或者有什么替代品吗?

目标:

基本上我正在更新我的应用程序中的文档。我正在使用分块更新,并且每次都必须通过新内容附加旧内容。

代码:

Blob bb = getDataAccess().executeScalar( "select content from Repository where id = ? for update", getId());
os = bb.setBinaryStream(startIndex + 1);

while ((read = content.read(buf)) > 0) {
    os.write(buf, 0, read);
    startIndex += read;

    //commit every megabate or every second so upload progress is visible
    //and we don't lose more than 1MB if something happens.

    if (startIndex - lastStartIndex > bufSize || (new Date().getTime() - lastUpdateTime) > UPDATE_INTERVAL) {
        os.close();
        os = null;
        getDataAccess().executeUpdate("UPDATE Repository SET LastChunkSaved = CURRENT_TIMESTAMP  WHERE ID = ?", getId());
        getDataAccess().commit();

        lastStartIndex = startIndex;
        lastUpdateTime = new Date().getTime();

        bb = getDataAccess().executeScalar( "select content from Repository where id = ? for update", getId());
        os = bb.setBinaryStream(startIndex + 1);

        totalSaved += startIndex - lastStartIndex;
    }
}
os.close();

【问题讨论】:

  • 类似的问题是here
  • 谢谢,我是 SQL 新手,看起来太难了。但我会尝试从中找到解决方案。

标签: java sql sql-server-2005 jdbc oracle10g


【解决方案1】:

我遇到了类似的问题,对我来说,将“SelectMethod=Cursor”添加到连接 url 有助于:

jdbc:sqlserver://<server>\SQLEXPRESS:1433;databaseName=<db>;SelectMethod=Cursor;integratedSecurity=true;

其实我不是很容易找到它,所以我将它添加到我会更快找到它的地方。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多