您好我试图创建一个包含数据库的活动,但是在运行应用程序时它显示一些语法错误并突然停止。我已经尝试调整语法上的空格,但它不起作用,我需要一些建议来克服我的错误。我在下面给我的日志猫
08-16 06:47:55.830: E/AndroidRuntime(1718): FATAL EXCEPTION: main
08-16 06:47:55.830: E/AndroidRuntime(1718): android.database.sqlite.SQLiteException: near "tableLOGINDETAILS": syntax error (code 1): , while compiling: create tableLOGINDETAILS( ID integer primary key autoincrement, USERNAME text , PASSWORD text , EMPLOYEE_CODE text , MOBILE integer );
08-16 06:47:55.830: E/AndroidRuntime(1718): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
08-16 06:47:55.830: E/AndroidRuntime(1718): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
08-16 06:47:55.830: E/AndroidRuntime(1718): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
这是代码
static final String DATABASE_NAME="LOGINDETAILS.db";
static final int DATABASE_VERSION=1;
public static final int NAME_COLUMN=1;
static final String DATABASE_CREATE = "create table"
// create a Sql query for database
+ "LOGINDETAILS"
+ "("
+ " ID "
+ "integer primary key autoincrement,"
+
" USERNAME text , PASSWORD text , EMPLOYEE_CODE text ,
MOBILE integer );" ;
public SQLiteDatabase db;
private final Context context;
private DataBaseHelper dbHelper;
public LoginDataBaseAdapter(Context _context)
{
context=_context;
dbHelper=new DataBaseHelper(_context, DATABASE_NAME, null,
DATABASE_VERSION);
}
public LoginDataBaseAdapter open()throws SQLException
{
db=dbHelper.getWritableDatabase();
return this;
}
public void close()
{
db.close();
}
public SQLiteDatabase getDatabaseInstance()
{
return db;
}
public void insertEntry(String User_name,String Password,String Emp_code,String
Mob)
{
ContentValues newValues=new ContentValues();
//Assign values for each column
newValues.put("USERNAME", User_name);
newValues.put("PASSWORD", Password);
newValues.put("EMPLOYEE_CODE", Emp_code);
newValues.put("MOBILE", Mob);
//Insert the row into the table
db.insert("LOGINDETAILS", null, newValues);
Toast.makeText(context, "User Info Saved", Toast.LENGTH_LONG).show();
}
//Method to delete a record of username
public int deleteEntry(String User_name)
{
String where ="USERNAME=?";
int numberOFEntriesDeleted=db.delete("LOGINDETAILS", where,new String[]
{User_name});
Toast.makeText(context, "No of entry deleted successfully :
"+numberOFEntriesDeleted, Toast.LENGTH_LONG).show();
return numberOFEntriesDeleted;
}
// method to get the password of the username
public String getSingleEntry(String User_name)
{
Cursor cursor=db.query("LOGINDETAILS", null, "USERNAME=?", new String[]
{User_name},null, null, null);
if(cursor.getCount()<1) //No user exist
return "NOT EXIST";
cursor.moveToFirst();
String Password=cursor.getString(cursor.getColumnIndex("PASSWORD"));
return Password;
}
// Method to update an existing record
public void updateEntry(String User_name,String Password)
{
//Create object of content values
ContentValues updatedValues=new ContentValues();
// Assign values for each item
updatedValues.put("USERNAME", User_name);
updatedValues.put("PASSWORD", Password);
String where="USERNAME=?";
db.update("LOGINDETAILS", updatedValues, where, new String[]
{User_name});
}
}