sqlite - Unable to insert data in sqllite database in android -


i have written contentvalues insertion, code compiles fine data not getting inserted in database. problem here that, tables getting created data not getting inserted, have no clue.

my code goes this: has 2 classes first class has database connection information , second class has table creation , data insertion statements.

class 2: create table , insert method has content values , returning value main class class 1: database connection , database open command. 

can please guide new android , trying learn on own.

here 2 classes 1 create database connection , other class insert user (using user class object) in database

public class userdatahelper extends sqliteopenhelper {  public userdatahelper(context context, string name, cursorfactory factory,         int version) {     super(context, name, factory, version);     // todo auto-generated constructor stub }  @override public void oncreate(sqlitedatabase database) {     // todo auto-generated method stub      database.execsql(usermatadata.sql);  }  @override public void onupgrade(sqlitedatabase arg0, int arg1, int arg2) {     // todo auto-generated method stub  } 

}

above class create database

public class userdatasource {  private sqlitedatabase userdatabase; private userdatahelper userdatahelper;   public userdatasource(context context) {     super();     userdatahelper = new userdatahelper(context, usermatadata.databasename, null, usermatadata.databaseversion);         }  public void opendatabase() {            userdatabase = userdatahelper.getreadabledatabase(); }  public void closedatabase() {     userdatahelper.close(); } public boolean adduser (user user) {     contentvalues cv = new contentvalues();     cv.put(usermatadata.name, user.getname());     cv.put(usermatadata.university, user.getuniversity());      long insert = userdatabase.insert(usermatadata.tablename, null, cv);     if( insert != -1)         return true;      return false;  }  public cursor getallusers() {     return userdatabase.query(usermatadata.tablename, null, null, null, null, null, null); } 

}

note user object object of user class can replace other stuff want add in database , change contentvalues accordingly


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -