Code sample: Updating table data

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.database.*;
import net.rim.device.api.io.*;

public class UpdateData extends UiApplication
{
    public static void main(String[] args)
    {
        UpdateData theApp = new UpdateData();
        theApp.enterEventDispatcher();
    }
    
    public UpdateData()
    {
        pushScreen(new UpdateDataScreen());
    }   
}

class UpdateDataScreen extends MainScreen
{
    Database d;
    public UpdateDataScreen()
    {
       LabelField title = new LabelField("SQLite Update Data Sample",
                                          LabelField.ELLIPSIS | 
                                          LabelField.USE_ALL_WIDTH);
       setTitle(title);
       add(new RichTextField("Trying to update data in MyTestDatabase.db."));
       try
       {
        URI myURI = URI.create("file:///SDCard/Databases/SQLite_Guide/" +
                               "MyTestDatabase.db"); 
        d = DatabaseFactory.open(myURI);
            
        Statement st = d.createStatement("UPDATE People SET Age=38 " +
                                         "WHERE Name='John'");
        st.prepare();
        st.execute();
        st.close();
        d.close();

        }
        catch ( Exception e ) 
        {         
            System.out.println( e.getMessage() );
            e.printStackTrace();
        }
             
    }
}

Was this information helpful? Send us your comments.