Código da DAO
package br.ufc.otavioguerra.dao;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import br.ufc.otavioguerra.modelo.Aluno;
public class AlunoDAO extends SQLiteOpenHelper{
private static final String DATABASE = "NomeDoBanco";
private static final int VERSAO = 2 ;
private static final String TABELA = "Alunos";
public AlunoDAO(Context ctx) {
super(ctx, DATABASE, null, VERSAO);
}
@Override
public void onCreate(SQLiteDatabase database) {
String sql = "CREATE TABLE " + TABELA + " ("
+ "id INTEGER PRIMARY KEY, "
+ "nome TEXT UNIQUE NOT NULL, "
+ "telefone TEXT, "
+"endereco TEXT, "
+"site TEXT, "
+"nota REAL, "
+"caminhoFoto TEXT, "
+");";
database.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
String sql = "DROP TABLE IF EXISTS " + TABELA;
database.execSQL(sql);
onCreate(database);
}
public void insere(Aluno aluno) {
ContentValues cv = new ContentValues();
cv.put("nome", aluno.getNome());
cv.put("telefone", aluno.getTelefone());
cv.put("endereco", aluno.getEndereco());
cv.put("site", aluno.getSite());
cv.put("nota", aluno.getNota());
cv.put("caminhoFoto", aluno.getCaminhoFoto());
getWritableDatabase().insert(TABELA,null,cv);
}
}