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

SQL Anywhere 12.0.0 (Français) » MobiLink - Getting Started » MobiLink Tutorials » Tutorial: Introduction to direct row handling » Lesson 4: Create a Java or .NET class for MobiLink direct row handling


Complete MobiLinkOrders code listing (Java)

The following is the complete MobiLinkOrders listing for Java direct row handling. For a step by step explanation, see Lesson 4: Create a Java or .NET class for MobiLink 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 reading in 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();