dimanche 1 février 2015

Inserting data in SQLite Database in Android

I am doing a project in Android and i have a problem about database. I created database in SQLite Browser and imported to my project in Android Studio. I can access database and select data from tables. But i can not insert data. I would be very happy if you help me. Thanks :)


Here's my code:



public boolean putInfo(String name, String surname, String username, String
mail, String pass, String address, String phone_no, String status) {
boolean res = true;
if (open()) {
List<User> users = getUsers();

for (int n = 0; n < users.size(); n++) {
String db_username = users.get(n).username;
String db_mail = users.get(n).mail;

if(db_username.equals(username) || db_mail.equals(mail)) {
res = false;
}
}

if(res == true) {
ContentValues cv = new ContentValues();
cv.put("uname",name);
cv.put("usurname",surname);
cv.put("uusername",username);
cv.put("upassword",pass);
cv.put("umail",mail);
cv.put("uaddress",address);
cv.put("ustatus",status);
cv.put("uphoneno",Integer.parseInt(phone_no));
db.insert("User", null, cv);
}
}
else {
// error opening DB.
}

return res;
}

Aucun commentaire:

Enregistrer un commentaire