Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 » MobiLink - Server Administration » MobiLink Server APIs » Writing synchronization scripts in Java » MobiLink server API for Java reference » DownloadTableData interface

 

getUpsertPreparedStatement method

Syntax
public java.sql.PreparedStatement getUpsertPreparedStatement( ) throws SQLException
Remarks

Returns a java.sql.PreparedStatement instance which allows the user to add upsert (insert or update) operations to the download of a synchronization. The prepared statement applies to the DownloadTableData instance and contains a parameter for each column in the table.

To include an insert or update operation in the download, set all column values in your java.sql.PreparedStatement and then call the java.sql.PreparedStatement.executeUpdate method. Calling java.sql.PreparedStatement.executeUpdate on the prepared statement returns 0 if the insert or update operation was filtered and returns 1 if the operation was not filtered. An operation is filtered if it was uploaded in the same synchronization.

Note

You must set all column values for download insert and update operations.

Returns

A java.sql.PreparedStatement instance for adding upsert operations to the download.

Exceptions
  • SQLException   Thrown if there is a problem retrieving the upsert java.sql.PreparedStatement instance.

See also
Example

In the following example, the setDownloadInserts method uses the DownloadTableData.getUpsertPreparedStatement to obtain a prepared statement for rows you want to insert or update. The java.sql.PreparedStatement.setInt and PreparedStatement.setString methods set the column values, and the PreparedStatement.executeUpdate method sets the row values in the download.

void setDownloadInserts(DownloadTableData td) { 
    java.sql.PreparedStatement insert_ps = td.getUpsertPreparedStatement();

    // This is the same as executing the following SQL statement:
    // INSERT INTO remoteOrders(pk, col1) VALUES (2300, "truck");
    insert_ps.setInt(1, 2300); 
    insert_ps.setString(2, "truck");

    int update_result = insert_ps.executeUpdate();
    if (update_result == 0) {
        // Insert was filtered because it was uploaded 
        // in the same synchronization.
    }
    else {
        // Insert was not filtered.
    }
    insert_ps.close();
}