android - insert id returns always -1 and data is not inserted in database. please somebody help me -
when insert data insert id returns -1 data base table.my database created successfully. so, please tell me solve problem.
query3 = "create table if not exists `" + staticdata.subject_table_name + "` (" + "`subject_id` int(11) not null," + "`subject_name` varchar(100) default null," + " primary key (`subject_id`)" + ");"; public long insertsubject(teachermodel queryvalues) { long insertid = -1; contentvalues values = new contentvalues(); values.put("id", queryvalues.getsubject_id()); values.put("name", queryvalues.getsubject()); if(database != null) { insertid = database.insert(staticdata.subject_table_name, null, values); } log.w(datainteract.class.getname(), "subject::" + values + "insertid=" + insertid); return insertid; }
there few things wrong code, check below corrections
as far see, insertid should equals subject_id try insert, if assumption not correct, need add different column in table.
things did wrong: table creation wrong, use mysql
code , not sqlite
, might work in cases not adviced. had wrong column names in values
(contentvalues()
), if database not exist, still -1.
query3 = "create table if not exists `" + staticdata.subject_table_name + "` (" + "`subject_id` integer primary key," + "`subject_name` text" + ");"; public long insertsubject(teachermodel queryvalues) { long insertid = -1; contentvalues values = new contentvalues(); values.put("subject_id", queryvalues.getsubject_id()); values.put("subject_name", queryvalues.getsubject()); if(database != null) { insertid = database.insert(staticdata.subject_table_name, null, values); } log.w(datainteract.class.getname(), "subject::" + values + "insertid=" + insertid); return insertid; }
Comments
Post a Comment