Changes

Jump to: navigation, search

Teams Winter 2011/team1/BlackBerry/Use SQLite

1,388 bytes added, 23:05, 11 April 2011
11.6 Create SQLiteManager Class
}
</source>
'''11.6.1 '''Open Database'''<br/>Then we implement the opemDBopenDB() method:
<source lang="java">
void openDB()
}
</source>
'''11.6.2 '''Close Database'''<br/>
Then we definitely need a closeDB() method to use later:
<source lang="java">
}
</source>
'''11.6.3 '''Insert 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">
//ADD STUDENT Student addStudent(String fName, String lName, String email, String address){ Student student = null; try { Statement statement = db.createStatement("INSERT INTO Student VALUES(NULL,?,?,?,?)"); statement.prepare(); statement.bind(1,fName); statement.bind(2, lName); statement.bind(3, email); statement.bind(4, address); statement.execute(); statement.close(); statement = db.createStatement("SELECT id FROM Student WHERE firstName = ? AND lastName = ?"); statement.prepare(); statement.bind(1, fName); statement.bind(2, lName); Cursor cursor = statement.getCursor(); if(cursor.next()) { Row row = cursor.getRow(); int id = row.getInteger(0); student = new Student(id, fName, lName, email, address); } cursor.close(); statement.close(); }catch(DatabaseException dbe) { errorDialog(dbe.toString()); } catch(DataTypeException dte) { errorDialog(dte.toString()); } return student; }
</source>
'''11.6.4 '''Delete Student'''<br/>
<source lang="java">
</source>
'''11.6.5 '''Update Student'''<br/>
<source lang="java">
</source>
'''11.6.6 '''Select All Students'''<br/>
gives us the list of all Students
<source lang="java">
1
edit

Navigation menu