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

SQL Anywhere 10.0.1 » MobiLink - Server Administration » Writing Synchronization Scripts in Java » MobiLink server API for Java Reference » DownloadTableData interface

getDeletePreparedStatement method Next Page

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 will return 0 if the insert or update operation was filtered and will return 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
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();
 }