android - Only one row can be inserted into SQLite database -
i tried extract data json , put database.
this inserted:
(int = 0; < listarray.length(); i++) { //extraction "time" , "weather_description" //............ //insertion: contentvalues values = new contentvalues(); //values.put(weatherentry._id,i); values.put(weatherentry.date_column, time); values.put(weatherentry.description_column, weather_description); getcontentresolver().insert(weatherentry.content_uri, values); }
sqliteopenhelper:
public class weatherdb extends sqliteopenhelper { private static final int database_version = 1; static final string database_name = "weather.db"; public weatherdb(context context) { super(context,database_name,null,database_version); } @override public void oncreate(sqlitedatabase sqlitedatabase) { string weather_query = "create table "+ weatherentry.weather_table_name+" ("+ weatherentry._id+" integer primary key autoincrement, "+ weatherentry.date_column+" text, "+ weatherentry.description_column+" text );"; sqlitedatabase.execsql(weather_query); } @override public void onupgrade(sqlitedatabase sqlitedatabase, int i, int i1) { } }
only first row (with
_id=0
) able go database.
i got error message: android.database.sqlite.sqliteconstraintexception: unique constraint failed: weather._id (code 1555)
try add autoincrement
instead on inserting i
:
weatherentry._id+" integer primary key autoincrement"
Comments
Post a Comment