我已经创建了一个SQLite Helper类来处理我的数据库。
我在运行代码时经常出现此错误,但我无法在Create Table语法中发现任何错误。
错误:android.database.sqlite.SQLiteException:靠近“table”:语法 错误(代码1):,编译时:CREATE TABLE表(ID INTEGER 主要自动跟踪,ACCOUNT_HOLDER TEXT,DEBIT INTEGER,CREDIT INTEGER,BALANCE INTEGER)
package com.example.user.balancesheet;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DatabaseHelper extends SQLiteOpenHelper{
private static final int DB_Version=1;
private static final String Database="BalanceSheet.db";
public static String Table="table";
public DatabaseHelper(Context context) {
super(context, Database, null, DB_Version);
SQLiteDatabase db=this.getWritableDatabase();
}
@Override
public void onCreate(SQLiteDatabase db) {
String query="CREATE TABLE " + Table +" (ID INTEGER PRIMARY KEY
AUTOINCREMENT, ACCOUNT_HOLDER TEXT, DEBIT INTEGER, CREDIT INTEGER,
BALANCE INTEGER)";
db.execSQL(query);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
db.execSQL("DROP IF EXIST " + Table);
onCreate(db);
}
public Boolean insertdata(String name, int deb, int cred, int bal){
ContentValues val=new ContentValues();
val.put("ACCOUNT_HOLDER", name);
val.put("DEBIT", deb);
val.put("CREDIT_HOLDER", cred);
val.put("BALANCE", bal);
SQLiteDatabase db=this.getWritableDatabase();
long result=db.insert(Table, null, val);
Log.d("METHOD","ADDLEDGER");
if(result==-1)
return false;
else
return true;
}
}