0

Above query runs successfully on Oracle 10g. Now I have to implement same query(Application) using SQLSERVER 2005.

When I am running Above Query in SQLSERVER 2005 I am getting error "FOR UPDATE clause allowed only for DECLARE CURSOR".

Is above query supported by SQLSERVER 2005? Or is there any alternate?

Aim:

Basicaly I am updating ducument in my application. I am using chunked update and I have to append every time old content by new content.

CODE:

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();
NathanOliver
  • 171,901
  • 28
  • 288
  • 402

1 Answers1

7

I ran into a similar problem and for me it helped to add 'SelectMethod=Cursor' to the connection url:

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

Actually I couldn't find this very easily so I add it here where I would have found it much quicker.

Bernd Ebertz
  • 1,317
  • 8
  • 10