0
我在我的應用程序內創建了一個SQLite數據庫。我試圖在TextView(android)中顯示內容,但是我有任何問題。SQLiteException:無法識別的令牌
數據庫:
CREATE TABLE "1_BASICA_1500" ("INDICACIONES" TEXT, "LUNES" TEXT, "MARTES" TEXT,
"MIERCOLES" TEXT, "JUEVES" TEXT, "VIERNES" TEXT, "SABADO" TEXT, "DOMINGO" TEXT,
"_ID" NUMERIC PRIMARY KEY NOT NULL)"
我Database.class
public class MyDataBase extends SQLiteAssetHelper {
private static final String DATABASE_NAME = "dietas.sqlite";
private static final int DATABASE_VERSION = 1;
public MyDataBase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public Cursor getDieta() {
SQLiteDatabase db = getReadableDatabase();
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
String [] sqlSelect = {"INDICACIONES", "LUNES", "MARTES", "MIERCOLES", "JUEVES", "VIERNES", "SABADO", "DOMINGO","_ID"};
String sqlTables = "1_BASICA_1500";
qb.setTables(sqlTables);
Cursor c = qb.query(db, sqlSelect, null, null,
null, null, null);
c.moveToFirst();
return c;
}
}
類展示內容:
public class DietaFragment extends Fragment {
Bundle paquete;
TextView txtDieta;
String nombre;
MyDataBase db;
Cursor cursor;
public DietaFragment(Bundle pack) {
// TODO Auto-generated constructor stub
paquete = pack;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_dieta, container, false);
txtDieta = (TextView) rootView.findViewById(R.id.txtDieta);
db = new MyDataBase(this.getActivity());
cursor = db.getDieta();
//nombre = paquete.getString("nombre");
txtDieta.setText(cursor.getString(0));
return rootView;
}
}
這裏是錯誤:
06-17 12:02:58.933: W/System.err(1630): android.database.sqlite.SQLiteException:
unrecognized token: "1_BASICA_1500" (code 1): , while compiling: SELECT INDICACIONES,
LUNES, MARTES, MIERCOLES, JUEVES, VIERNES, SABADO, DOMINGO, _ID FROM 1_BASICA_1500
如果可以幫我請,謝謝收看!
感謝我改名字,但現在我有其他錯誤:(1)沒有這樣的表:BASICA1 – Phantomluffy
@Phantomluffy你實際創建BASICA1表?注意:要確保再次創建數據庫,請增加DATABASE_VERSION。 – matiash
對不起,我在那個菜鳥:(現在我有其他問題 升級數據庫dietas.sqlite從版本1到2 ... 缺少數據庫升級腳本:databases/dietas.sqlite_upgrade_1-2.sql 沒有升級腳本路徑從1到2 無法打開dietas.sqlite寫入(將嘗試只讀): – Phantomluffy