Esempio di codice: utilizzo delle transazioni

/*
* UsingTransactions.java
*
* Research In Motion Limited proprietary and confidential
* Copyright Research In Motion Limited, 2010
*/
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 UsingTransactions extends UiApplication
{
	public static void main(String[] args)
	{
		UsingTransactions theApp = new UsingTransactions();
		theApp.enterEventDispatcher();
	}
	public UsingTransactions()
	{
	}
}
class UsingTransactionsScreen extends MainScreen
{
	Database d;
	public UsingTransactionsScreen()
	{
		LabelField title = new LabelField("SQLite Using Transactions Sample",
		LabelField.ELLIPSIS |
		LabelField.USE_ALL_WIDTH);
		setTitle(title);
		add(new RichTextField("Trying to update data in a single transaction in MyTestDatabase.db."));
		try
		{
			URI myURI = URI.create("file:///SDCard/Databases/SQLite_Guide/" +
			"MyTestDatabase.db");
			d = DatabaseFactory.open(myURI);
			d.beginTransaction();
			Statement st = d.createStatement("UPDATE People SET Age=7 " +
			"WHERE Name='Sophie'");
			st.prepare();
			st.execute();
			st.reset();
			st = d.createStatement("UPDATE People SET Age=4 " +
			"WHERE Name='Karen'");
			st.prepare();
			st.execute();
			d.commitTransaction();
            st.close();
            d.close();
		}
		catch ( Exception e )
		{
			System.out.println( e.getMessage() );
			e.printStackTrace();
		}
	}
}

Le informazioni sono state utili? Inviateci i vostri commenti.