我有一个包含这些列的表:
import java.util.prefs.Preferences;
public class DataClass {
public void createPreference(String name, int value) {
Preferences prefs = Preferences.userNodeForPackage(DataClass.class);
if (prefs.getInt(name, -1) == -1) {
prefs.putInt(name, value);
System.out.println("Created For you, "+name+" with value: "+value);
} else {
System.out.println("Already Exist");
}
}
public int readPreference(String name) {
Preferences prefs = Preferences.userNodeForPackage(DataClass.class);
return prefs.getInt(name, -1);
}
public void updatePreference(String name) {
Preferences prefs = Preferences.userNodeForPackage(DataClass.class);
int val = prefs.getInt(name, -1);
if (val != -1) {
val++;
prefs.remove(name);
prefs.putInt(name, val);
System.out.println("New Value of "+name+" is: "+prefs.getInt(name, -1));
}
}
public void removePreference(String key) {
Preferences prefs = Preferences.userNodeForPackage(DataClass.class);
if(prefs.getInt(key, -1) != -1){
prefs.remove(key);
System.out.println("Removed: "+key);
}else{
System.out.println("No Such Data in: "+key);
}
}
}
我创建了一个跟随值的记录
id, exchange, name
然后我查询它,其中有 na, "ted1", "ted1-curA"
。
exchange=ted1
引发了 database.query(true, "cur", null, null
, null, "name","exchange=name1", null, null);
测试代码是
no such column name1
答案 0 :(得分:0)
name1应该是单引号,例如" exchange =' name1'"
构建dataBases的最佳方法是在分离的类中使用常量 请创建一个常量类,并将所有数据库常量放在那里:
public static final String DATA_BASE_NAME = "appStructure.db";
public static final int DATA_BASE_VERSION = 1;
public static final String TABLE_NAME = "Data_Table";
public static final String COLUMN_IDS = "_id";
public static final String COLUMN_TITLE = "Titles";
public static final String COLUMN_CONTENT = "Contents";
public static final String COLUMN_IMAGE = "Images";
public static final String COLUMN_LOCATION = "Location";
public static final String CREATE_DB_TABLE_COMMAND = "CREATE TABLE
"+TABLE_NAME+"( "+COLUMN_ID+" INTEGER PRIMARY KEY AUTOINCREMENT,
"+COLUMN_TITLE+" TEXT, "+COLUMN_CONTENT+" TEXT, "+COLUMN_IMAGE+" BLOB,
"+COLUMN_LOCATION+" TEXT"+");";
并轻松地在项目中使用它们。