1
edit
Changes
→11.6 Create SQLiteManager Class
Now we need a class that will be the only class interacting with our database. It will take a Database object and a URI object to open database in the constructor. It will have methods to perform all the queries we need and at the end of each query will close the database. <br/>
So, create a class called: SQLiteManager, with 2 private fields , and a constructor that sets them and then tries to open database:
<source lang="java">
private static Database db;
private URI uri;
public SQLManager(Database db, URI uri)
{
this.uri = uri;
this.db = db;
openDB();
}
}
</source>
11.6.1 Open Database<br/>
Then we implement the opemDB() method:
<source lang="java">
void openDB()
{
try
{
this.db = DatabaseFactory.open(uri);
}
catch(DatabaseException dbe)
{
errorDialog(dbe.toString());
}
}
</source>
11.6.2 Close Database<br/>
Then we definitely need a closeDB() method to use later:<source lang="java"> static void closeDB() { try { db.close(); } catch(DatabaseException dbe) { errorDialog(dbe.toString()); } } </source>And as you noticed above, we are going to need a method called errorDialog():<source lang="java"> public static void errorDialog(final String message) { UiApplication.getUiApplication().invokeLater(new Runnable() { public void run() { Dialog.alert(message); } }); }</source>11.6.3 Select All StudentsInsert New Student<br/>The first query we need is a query that enables us add a new Student, so we need to implement a method for that: <source lang="java"> </source>11.6.4 Insert New StudentSelect All Students<br/> gives us the list of all Students<source lang="java"> </source>
11.6.5 Delete Student<br/>
<source lang="java">
</source>
11.6.6 Update Student<br/>
<source lang="java">
</source>
===11.7 Modify StudentsList Class to use SQLiteManager===