Note that there are some explanatory texts on larger screens.

plurals
  1. POupdating or inserting in a table with keeping the row numbers to one
    primarykey
    data
    text
    <p>I am trying to see if there is something in my table update it and if not insert one row. So basically I will have one row always in my table. </p> <pre><code> public void createOrupdate(long id,String x, String y, String angle){ String[] columns= new String[]{KEY_ROWID, KEY_X, KEY_Y, KEY_ANGLE}; Cursor c= ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null); ContentValues editCon = new ContentValues(); if (c!=null){ editCon.put(KEY_X, x); editCon.put(KEY_Y, y); editCon.put(KEY_ANGLE, angle); ourDatabase.update(DATABASE_TABLE, editCon, KEY_ROWID + "=?", new String[]{String.valueOf(id)}); } else{ editCon.put(KEY_X, x); editCon.put(KEY_Y, y); editCon.put(KEY_ANGLE, angle); ourDatabase.insert(DATABASE_TABLE, null, editCon); } } public String getData() { // TODO Auto-generated method stub String[] columns= new String[]{KEY_ROWID, KEY_X, KEY_Y, KEY_ANGLE}; Cursor c= ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null); String result= ""; int iRow= c.getColumnIndex(KEY_ROWID); int iX= c.getColumnIndex(KEY_X); int iY= c.getColumnIndex(KEY_Y); int iAngle= c.getColumnIndex(KEY_ANGLE); int i= 0; for( c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){ result= result+ c.getString(iRow)+ " "+ c.getString(iX)+ " " +c.getString(iY)+ " "+ c.getString(iAngle)+"\n"; } return result; } </code></pre> <p>But when I use <code>entry.createOrupdate(1, Double.toString(db1), Double.toString(db2), Double.toString(db3));</code> in my code there is nothing in my table and no exception and nothing. when i use update or insert separately it works.. what is the problem?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload