Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid SQL database Error while creating
    primarykey
    data
    text
    <p>I've made an E- Mail client for my Android Phone, and now I want to save the E- Mails in a SQLite database. But if I want to fill the Database only with test data, I this Error:</p> <blockquote> <p>E/SQLiteLog(21212): (1) near "TO": syntax error</p> <p>E/SQLiteDatabase(21212): Error inserting SUBJECT=test subject TO=emailadress2 FROM=emailadress1 CONTENT=test content</p> <p>android.database.sqlite.SQLiteException: near "TO": syntax error (code 1): , while compiling: INSERT INTO MAIL(SUBJECT,TO,FROM,CONTENT) VALUES (?,?,?,?)</p> <p>(...)</p> <p>(1) near "FROM": syntax error</p> <p>E/Error(21212): android.database.sqlite.SQLiteException: near "FROM": syntax error (code 1): , while compiling: SELECT ID, FROM, TO, SUBJECT, CONTENT FROM MAIL WHERE ID = -1</p> </blockquote> <p>I use the following code for the database:</p> <p>MAINACTIVITY.java</p> <pre><code>public void dbCreate(View view){ String from = "emailadress1"; String to = "emailadress2"; String subject = "test subject"; String content = "test content"; try { datasource.open(); datasource.createEntry(from, to, subject, content); datasource.close(); } catch (Exception ex) { Toast.makeText(this,"Error", Toast.LENGTH_LONG).show(); Log.e("Error", ex.toString()); } } </code></pre> <p>MYSQLiteHelper.java</p> <pre><code>private static final String DATABASE_NAME = "mail.db"; private static final int DATABASE_VERSION = 1; private static final String TABLE_CREATE_MAIL = "CREATE TABLE MAILS ( ID integer PRIMARY KEY AUTOINCREMENT, FROM TEXT, TO TEXT, SUBJECT TEXT, CONTENT TEXT);"; public MySQLiteHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase database) { Log.i("Info", "OnCreate aufgerufen"); database.execSQL(TABLE_CREATE_MAIL); } </code></pre> <p>DATASOURCE.java</p> <pre><code>private SQLiteDatabase database; private MySQLiteHelper dbHelper; private String[] allColumns = { "ID", "FROM", "TO", "SUBJECT", "CONTENT"}; public Entry createEntry(String from, String to, String subject, String content) { ContentValues values = new ContentValues(); values.put("FROM", from); values.put("TO", to); values.put("SUBJECT", subject); values.put("CONTENT", content); long insertId = database.insert("MAIL", null, values); Cursor cursor = database.query("MAIL",allColumns, "ID = " + insertId, null, null, null, null, null); cursor.moveToFirst(); return cursorToEntry(cursor); } </code></pre>
    singulars
    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.
 

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