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

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


getUpsertPreparedStatement method

public java.sql.PreparedStatement getUpsertPreparedStatement( ) throws SQLException

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.


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


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

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

See also

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.