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 - Getting Started » Tutorial: Using Direct Row Handling » Lesson 3: Write Java or .NET logic for processing direct row handling

Lesson 3: Write Java or .NET logic for processing direct row handling Next Page

Complete MobiLinkOrders listing (Java)

Following is the complete MobiLinkOrders listing for Java direct row handling. For a step by step explanation, see Lesson 3: Write Java or .NET logic for processing direct row handling.

import java.sql.*;

public class MobiLinkOrders {

 // class level DBConnectionContext
    DBConnectionContext _cc;
    // java objects for file i/o
    FileWriter my_writer;
    BufferedReader my_reader;
    public MobiLinkOrders( DBConnectionContext cc )
     throws IOException, FileNotFoundException
  // declare a class-level DBConnectionContext
     _cc = cc; 
    public void writeOrderComment( int _commentID, int _orderID, String _comments ) 
 throws IOException
     if(my_writer == null)
      // a FileWriter for writing order comments
       my_writer = new FileWriter( "C:\\MLdirect\\orderComments.txt",true);
  // write out the order comments to remoteOrderComments.txt
  my_writer.write(_commentID + "\t" + _orderID + "\t" + _comments);
  my_writer.write( "\n" );
    //  method for the handle_UploadData synchronization event
    public void GetUpload( UploadData ut ) throws SQLException, IOException
    //  get an UploadedTableData for OrderComments
    UploadedTableData orderCommentsTbl = ut.getUploadedTableByName("OrderComments");
 // get inserts uploaded by the MobiLink client
 ResultSet insertResultSet = orderCommentsTbl.getInserts();
 while( ) { 
  // get order comments
  int _commentID = insertResultSet.getInt("comment_id");
  int _orderID = insertResultSet.getInt("order_id");
  String _specialComments = insertResultSet.getString("order_comment");
  if (_specialComments != null)

 public void SetDownload() throws SQLException, IOException
  DownloadData download_d = _cc.getDownloadData();
  DownloadTableData download_td = download_d.getDownloadTableByName( "OrderComments" );
  PreparedStatement update_ps = download_td.getUpsertPreparedStatement();
    // a BufferedReader for writing out responses
  if (my_reader==null)
     my_reader = new BufferedReader(new FileReader( "c:\\MLdirect\\orderResponses.txt"));
  // get the next line from orderResponses
  String commentLine;
  commentLine = my_reader.readLine();
  //   send comment responses down to clients
  while(commentLine != null)
//    get the next line from orderResponses.txt
   String[] response_details = commentLine.split("\t");

   if (response_details.length != 3)
    System.err.println("Error reading from orderResponses.txt");
    System.err.println("Error setting direct row handling download");
   int comment_id = Integer.parseInt(response_details[0]);
   int order_id = Integer.parseInt(response_details[1]);
   String updated_comment = response_details[2];

   // set an order comment response in the MobiLink download
   update_ps.setInt(1, comment_id);
   update_ps.setInt(2, order_id);
   update_ps.setString(3, updated_comment);
   // get next line
   commentLine  = my_reader.readLine();
 public void EndDownload() throws IOException
   // close i/o resources
     if (my_reader!=null) my_reader.close();
     if (my_writer!=null) my_writer.close();