|
|
|
Android ผมสร้าง SQLite แต่มีปัญหาตอน Insert ข้อมูลครับ "E/SQLiteLog: (1) near "TABLEmembersMemberID": syntax error" |
|
|
|
|
|
|
|
มันขึ้น Error แบบภาพนี้ครับ
[/head]
05-12 16:43:35.979 15176-15176/com.example.rattapongt.androidproject E/SQLiteLog: (1) near "TABLEmembersMemberID": syntax error
คือผมเอาโค๊ดเดิมมาจากในเว็บนี้ก็รันได้ปกติครับ แต่พอมาปรับใช้เองกลับ error รบกวนด้วยครับ
[head]myDBClass)
package com.example.rattapongt.androidproject;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class myDBClass extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "mydatabase";
private static final String TABLE_MEMBER = "members";
public myDBClass(Context context){
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE" + TABLE_MEMBER + "MemberID INTEGER PRIMARY KEY AUTOINCREMENT," +
"Pass NOT NULL," +
"Name NOT NULL," +
"Tel NOT NULL," +
"Email NOT NULL," +
"Address NOT NULL);");
Log.d("CREATE TABLE","Create Table Successfully");
}
public long InsertData(String strMemberID, String strPassword, String strName, String strTel, String strEmail, String strAddress){
try {
SQLiteDatabase db;
db = this.getWritableDatabase();
ContentValues Val = new ContentValues();
Val.put("MemberID", strMemberID);
Val.put("Pass", strPassword);
Val.put("Name", strName);
Val.put("Tel", strTel);
Val.put("Email", strEmail);
Val.put("Address", strAddress);
long rows = db.insert(TABLE_MEMBER, null, Val);
return rows;
}catch (Exception e){
return -1;
}
}
public String[] SelectData(String strMemberID){
try {
String arrData[] = null;
SQLiteDatabase db;
db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_MEMBER, new String[] { "*" },
"MemberID=?",
new String[] { String.valueOf(strMemberID) }, null, null, null, null);
if (cursor != null)
{
if (cursor.moveToFirst()){
arrData = new String[cursor.getColumnCount()];
arrData[0] = cursor.getString(0);
arrData[1] = cursor.getString(1);
arrData[2] = cursor.getString(2);
arrData[3] = cursor.getString(3);
arrData[4] = cursor.getString(4);
arrData[5] = cursor.getString(5);
}
}
cursor.close();
db.close();
return arrData;
}catch (Exception e){
return null;
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS" + "members");
onCreate(db);
}
}
Tag : Mobile, Android, JAVA
|
|
|
|
|
|
Date :
2016-05-12 17:01:04 |
By :
rattapongza |
View :
1161 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2016-05-13 09:01:47 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|