执行我的Android应用程序时出现此错误。我在一个名为MySQLitehelper.java的文件中创建了SQLite数据库,该文件包含以下用于创建表的行:
public static final String COLUMN_ID = "GWid";
public static final String COLUMN_DATE = "DateGWU";
public static final String COLUMN_LOCATION = "location";
public static final String COLUMN_TIME = "time";
public static final String TABLE_NAME = "UPDTable";
private static final String DATABASE_NAME = "UPDdb_version6";
private static final int DATABASE_VERSION = 6;
private final Context context;
GetSet getset = new GetSet();
public void GetIdForGwid(GetSet get)
{
getset=get;
}
// Database creation sql statement
private static final String DATABASE_CREATE = "CREATE TABLE " + TABLE_NAME +
" (" +COLUMN_ID+ " integer," + COLUMN_DATE + "VARCHAR," +
COLUMN_LOCATION+" VARCHAR," +COLUMN_TIME +" VARCHAR);";
private static final String DATABASE_INSERT = "INSERT INTO " +TABLE_NAME +
" Values (47688507,'DEC-07-2012','MARVIN 203','20:00');";
在同一个文件中我有执行我的SQL SELECT查询的语句,但是给我一个例外,没有找到这样的列DateGWU
public Cursor getRecord() throws SQLException
{
Cursor mCursor =
db.query(true, TABLE_NAME, new String[] {COLUMN_ID,
COLUMN_DATE, COLUMN_LOCATION, COLUMN_TIME},
COLUMN_ID + "= 47688507", null, null, null, null, null); //HARDCODED. Please make it dynamic
if (mCursor != null)
{
mCursor.moveToFirst();
}
return mCursor;
}
我有点卡住了,不知道我哪里出错了。
11-30 04:57:50.832: E/SQLiteLog(12912): (1) no such column: DateGWU
11-30 04:57:50.842: D/AndroidRuntime(12912): Shutting down VM
11-30 04:57:50.852: W/dalvikvm(12912): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
11-30 04:57:50.952: E/AndroidRuntime(12912): FATAL EXCEPTION: main
11-30 04:57:50.952: E/AndroidRuntime(12912): android.database.sqlite.SQLiteException: no such column: DateGWU (code 1): , while compiling: SELECT DISTINCT GWid, DateGWU, location, time FROM UPDTable WHERE GWid= '47688507'
11-30 04:57:50.952: E/AndroidRuntime(12912): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
11-30 04:57:50.952: E/AndroidRuntime(12912): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
11-30 04:57:50.952: E/AndroidRuntime(12912): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
11-30 04:57:50.952: E/AndroidRuntime(12912): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
11-30 04:57:50.952: E/AndroidRuntime(12912): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
11-30 04:57:50.952: E/AndroidRuntime(12912): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
11-30 04:57:50.952: E/AndroidRuntime(12912): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
11-30 04:57:50.952: E/AndroidRuntime(12912): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
11-30 04:57:50.952: E/AndroidRuntime(12912): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
11-30 04:57:50.952: E/AndroidRuntime(12912): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
11-30 04:57:50.952: E/AndroidRuntime(12912): at com.example.upd.MySQLitehelper.getRecord(MySQLitehelper.java:125)
答案 0 :(得分:7)
你有
private static final String DATABASE_CREATE = "CREATE TABLE " + TABLE_NAME +
" (" +COLUMN_ID+ " integer," + COLUMN_DATE + "VARCHAR," +
COLUMN_LOCATION+" VARCHAR," +COLUMN_TIME +" VARCHAR);";
将其更改为
private static final String DATABASE_CREATE = "CREATE TABLE " + TABLE_NAME +
" (" +COLUMN_ID+ " integer," + COLUMN_DATE + " VARCHAR," +
COLUMN_LOCATION+" VARCHAR," +COLUMN_TIME +" VARCHAR);";
注意空格:
COLUMN_DATE +“VARCHAR”,
COLUMN_DATE +“VARCHAR”,
答案 1 :(得分:3)
请更改数据库插入声明
private static final String DATABASE_INSERT = "INSERT INTO " +TABLE_NAME + " (" +COLUMN_ID+ " ," + COLUMN_DATE + "," +
COLUMN_LOCATION+" ," +COLUMN_TIME +" )" +
" Values (47688507,'DEC-07-2012','MARVIN 203','20:00');";
答案 2 :(得分:0)
尝试将数据库名称从“ UPDdb_version6”更改为“ UPDdb_version6.db”,即
private static final String DATABASE_NAME = "UPDdb_version6";
收件人
private static final String DATABASE_NAME = "UPDdb_version6.db";