SQLite的Andr​​oid的原始查询INSERT INTO不工作 [英] Sqlite Android Raw Query INSERT INTO Not Working

查看:166
本文介绍了SQLite的Andr​​oid的原始查询INSERT INTO不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想插入一些排在Android的一个表,我使用的是这样的:

I wanna insert some row to a table in Android, I'm using this:

INSERT INTO MyTable (Column_1, Column_1) VALUES ('X',100);

在查询运行没有异常被抛出,但是当我检索 MyTable的中的所有行,没有行
被返回。

The query runs and no exception is thrown, but when I retrieve all rows from MyTable, no row is returned.

我不想使用插入方法,因为查询是从文件中读取,我想将它们插入到数据库中。

I do not want to use the insert method, because the queries are read from a file and I want to insert them to the database.

这有什么错我的code?

What's wrong with my code?

更新:在 rawQuery()方法不会运行查询,但 execSQL()一样。

Update : The rawQuery() method doesn't run the query, but execSQL() does.

推荐答案

你的问题的标题建议你使用<一个href=\"http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#rawQuery%28java.lang.String,%20java.lang.String%5B%5D%29\"相对=nofollow> rawQuery() 。它只是编译SQL,但不运行它。呼吁的的moveTo ...()方法之一返回光标也将执行SQL。

The title of your question suggests you're using rawQuery(). It just compiles the SQL but does not run it. Calling one of the moveTo...() methods on the returned Cursor would also execute the SQL.

有关插入查询,使用<一个href=\"http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#execSQL%28java.lang.String,%20java.lang.Object%5B%5D%29\"相对=nofollow> execSQL() 而不是 rawQuery(),即使文档不正确各州它不应与使用插入

For an insert query, use execSQL() instead of rawQuery(), even if the documentation incorrectly states it should not be used with INSERT.

这篇关于SQLite的Andr​​oid的原始查询INSERT INTO不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆