2012-04-06 96 views
0

當準備'創建表選項...創建表分數時,錯誤會提示類似(接近「創建」:語法錯誤)...我只會在程序中發佈所有其他代碼當遇到更多問題時我可以問。Android - SQLite創建表錯誤

這是我的表(DBHelper.java):

final static String sqlcreate=

 "create table option (id integer primary key autoincrement," + 
     "volume boolean not null, vibrate boolean not null, theme text not null) " +  

     "create table score (id integer primary key autoincrement," + 
     "score text not null, difficulty text not null, date date not null,);"; 

這是我DBFunction.java:

public int addScore(String score, String difficulty){

ContentValues values = new ContentValues();

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 
    Date scoredate = new Date();  
    values.put("score", score); 
    values.put("difficulty", difficulty); 
    values.put("date", dateFormat.format(scoredate)); 
    return (int) db.insert(tableScore, null, values); 
}` 

,這是我的OnClick():

if (v==btnadd){

 String vol = tbtnvol.getText().toString(); 
     String vib = tbtnvib.getText().toString(); 
     String theme = themename.getText().toString(); 
     options.open(); 
     options.addOption(vol, vib, theme); 
     options.close(); 
     Toast.makeText(this, "Data has been added", Toast.LENGTH_LONG).show(); 
    }` 

回答

0

您需要兩個SQL語句在那裏用分號分隔。

... theme text not null); " + <-- semi colon added here 
"create table score ... 
1

如下修正您的查詢:

"create table option (id integer primary key autoincrement," + 
"volume boolean not null, vibrate boolean not null, theme text not null); " + 

"create table score (id integer primary key autoincrement," + 
"score text not null, difficulty text not null, date date not null);"; 

你已經錯過了分號,並在查詢中留下了一個額外的逗號

+0

哦,它不包括在我的查詢中,對不起。它應該是「'」,這是你在編寫代碼時在這裏輸入的在stackoverflow中。我只是修復..我會先嚐試將我的表分成不同的變量。 – 2012-04-06 18:04:48

0

第一個查詢沒有錯誤

create table option (id integer primary key autoincrement,volume boolean not null, vibrate boolean not null, theme text not null) 

第二查詢

create table score (id integer primary key autoincrement," + 

「得分文不爲空,難度文字不爲空,日日不爲空)

我檢查了,現在它工作正常

0

刪除,從最終

"create table score (id integer primary key autoincrement," + 
    "score text not null, difficulty text not null, date date not null,);"; 

寫如下

"create table score (id integer primary key autoincrement," + 
    "score text not null, difficulty text not null, date date not null);"; 

是的,也放了;最後,因爲格雷厄姆說