android - while compiling: INSERT INTO tabellirik(judul,lirikpupuh) VALUES (?,?) -
i have problem sqlite
error table tabellirik has no column named judul (code 1): , while compiling: insert tabellirik(judul,lirikpupuh) values (?,?)
i have same error, , have question, location file database sqlite if debug application, im using android studio?
please me :)
public class dbhelper extends sqliteopenhelper { private static final int database_version = 1; private static final string database_name = "macepat"; private static final string table_mupuh = "tabellirik"; private static final string key_id = "id"; private static final string judul = "judul"; private static final string key_mupuh = "lirikpupuh"; public dbhelper(context context){ super(context, database_name, null, database_version); } @override public void oncreate(sqlitedatabase db) { string create_lirik_table = "create table " + table_mupuh + "(" + key_id + " integer primary key," + judul + "text," + key_mupuh + "text)"; db.execsql(create_lirik_table); } @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { db.execsql("drop table if exists" + table_mupuh); oncreate(db); } public int addlirik(lirik lirik){ sqlitedatabase db = this.getwritabledatabase(); contentvalues values = new contentvalues(); values.put(judul, lirik.getjudul()); values.put(key_mupuh, lirik.getlirik()); int id = (int) db.insert(table_mupuh,null,values); db.close(); return id; } public int editlirik(lirik lirik, string position){ sqlitedatabase db = this.getwritabledatabase(); contentvalues values = new contentvalues(); values.put(judul, lirik.getjudul()); values.put(key_mupuh, lirik.getlirik()); return db.update(table_mupuh, values, key_id + " = ?", new string[] {string.valueof(position)}); } public boolean deletelirik(long idlirik){ sqlitedatabase db = this.getwritabledatabase(); return db.delete(table_mupuh,key_id + "= " + idlirik, null)>0; } public lirik getlirik(string id){ sqlitedatabase db = this.getreadabledatabase(); cursor cursor = db.query(table_mupuh, new string[] { key_id , judul, key_mupuh}, key_id + "=?", new string[] {string.valueof(id)}, null, null, null); if (cursor != null) cursor.movetofirst(); lirik lirik = new lirik(cursor.getstring(1), cursor.getstring(2)); db.close(); return lirik; } public string[] getalllirik(){ arraylist<string> liriklist = new arraylist<string>(); string selectquery = "select * " + table_mupuh; try { sqlitedatabase db = this.getreadabledatabase(); cursor cursor = db.rawquery(selectquery,null); if (cursor.movetofirst()){ { string lirik = cursor.getstring(1) +" , "+ cursor.getstring(2) + " , " + cursor.getstring(3); liriklist.add(lirik); }while (cursor.movetonext()); } string [] liriks = new string[liriklist.size()]; db.close(); return (liriklist.toarray(liriks)); } catch (exception e){ log.d("error", e.getmessage()); return null; } } }
thanks
your table not created because have missed spaces on create
statement, , insert
cannot compiled against non-existing table:
string create_lirik_table = "create table " + table_mupuh + "(" + key_id + " integer primary key," + judul + " text," + key_mupuh + " text)";
also, have missed spaces on drop
statement:
db.execsql("drop table if exists " + table_mupuh);
Comments
Post a Comment