android - Create SQL table, SQLite Exception -
know elementary question, keep on getting error code on logcat:
android.database.sqlite.sqliteexception: near "select_id": syntax error (code 1): , while compiling: select_id, name,password gandalf order name
would need advice, have tried looking @ other create sqlite table post couldnt solve it.
public void oncreate(sqlitedatabase db) { db.execsql("create table gandalf " + "(_id integer primary key autoincrement,name text,password text, category text);"); }
and try too
db.execsql("create table books ( " + "id integer primary key autoincrement, " + "name text, "+ "password text, "+ "category text)");
full code datahelper public class datahelp extends sqliteopenhelper{
private static final string dbname = "pass.db"; private static final int ver = 1; public datahelp(context context) { super(context, dbname, null, ver); // todo auto-generated constructor stub } @override public void oncreate(sqlitedatabase db) { db.execsql("create table gandalf " + "(_id integer primary key autoincrement,name text,password text, category text);"); } @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { // todo auto-generated method stub } public void insertdb(string name, string pass){ sqlitedatabase db = this.getwritabledatabase(); contentvalues cv = new contentvalues(); cv.put("name", name); cv.put("pass", pass); db.insert("db", null, cv); db.close(); } public cursor getall(){ return (getreadabledatabase().rawquery("select_id, name," + "password gandalf order name",null)); } public string getname(cursor c){ return(c.getstring(1)); } public string getpass(cursor c) { return(c.getstring(2)); } public string getcat(cursor c) { return(c.getstring(3)); }
}
add whitespace after select
in sql
command
db.rawquery("select _id, name, password gandalf order name",null);
Comments
Post a Comment