数据库(3300):sqlite的返回:错误code = 1,味精=没有这样的表:但表名是检验? [英] Database(3300): sqlite returned: error code = 1, msg = no such table: But the tables name is inspection?
问题描述
我试图将数据插入到一个表,是一个更大的项目的一部分。我收到上述错误并不能弄清楚如何创建表。创建该表的code是下方的表名是检查。所以,我很迷茫。
这里是logcat的信息
02-27 18:38:45.956:I /数据库(3559):sqlite的返回:错误code = 1,味精=没有这样的表:检查
02-27 18:38:45.967:E /数据库(3559):错误插入co_driver = =驱动ewrre vehicle_id = ET 432状态= 1 DATE_TIME = 40 =汽车类型卡车
02-27 18:38:45.967:E /数据库(3559):android.database.sqlite.SQLiteException:没有这样的表:检查:,在编译:INSERT INTO检查(co_driver,司机,vehicle_id,地位,DATE_TIME,汽车类型) VALUES(?,,,,,?????);
02-27 18:38:45.967:E /数据库(3559):在android.view.View.performClick(View.java:2408)
下面是创建该表的code
私有静态最后弦乐DATABASE_CREATE =创建表检查(
+_id整数主键自动增量
+vehicle_id字符串不为空,
+汽车类型的字符串不为空,
+日期时间整数不为空,
+驱动程序字符串不为空,
+codriver字符串
+状态整数非空
+);;公共静态无效的onCreate(SQLiteDatabase数据库){
database.execSQL(DATABASE_CREATE);
}公共静态无效onUpgrade(SQLiteDatabase数据库,诠释oldVersion,诠释静态网页){
Log.w(InspectionsTable.class.getName()+ oldVersion +到+ NEWVERSION +从版本升级数据库,这将摧毁所有旧数据);
database.execSQL(DROP TABLE IF EXISTS检查);
的onCreate(数据库);
}
这是DBhelper类
公共类SignalSetDBHelper扩展SQLiteOpenHelper {
私有静态最后弦乐DATABASE_NAME =DB;
私有静态最终诠释DATABASE_VERSION = 1;公共SignalSetDBHelper(上下文的背景下){
超(背景下,DATABASE_NAME,空,DATABASE_VERSION);
}//方法是创建数据库中调用
@覆盖
公共无效的onCreate(SQLiteDatabase DB){
CurrentStateTable.onCreate(DB);
HoursOfServiceTable.onCreate(DB);
InspectionsTable.onCreate(DB);
}//方法的数据库在升级过程中被调用时,
//例如如果增加数据库版本
@覆盖
公共无效onUpgrade(SQLiteDatabase数据库,诠释oldVersion,诠释静态网页){
CurrentStateTable.onUpgrade(数据库,oldVersion,NEWVERSION);
HoursOfServiceTable.onUpgrade(数据库,oldVersion,NEWVERSION);
}
}
这是适配器类
公共类InspectionDBAdapter {
私有静态最后弦乐KEY_ROWID =_ ID;
私有静态最后弦乐KEY_VEHICLE_ID =vehicle_id;
私有静态最后弦乐KEY_VEHICLE_TYPE =汽车类型;
私有静态最后弦乐KEY_DATETIME =DATE_TIME;
私有静态最后弦乐KEY_DRIVER =驱动程序;
私有静态最后弦乐KEY_CO_DRIVER =co_driver;
私有静态最后弦乐KEY_STATUS =身份;
私有静态最后弦乐DB_TABLE =检查;
私人上下文的背景下;
私人SQLiteDatabase分贝;
私人SignalSetDBHelper dbHelper;公共InspectionDBAdapter(上下文的背景下){
this.context =背景;
}公共InspectionDBAdapter的open()抛出的SQLException {
dbHelper =新SignalSetDBHelper(背景);
DB = dbHelper.getWritableDatabase();
返回此;
}公共无效的close(){
dbHelper.close();
}公共无效insertInspection(字符串vehicle_id,字符串汽车类型,
INT日期时间,串驱动器,串codriver,诠释状态)
{ ContentValues newContact = createContentValue(vehicle_id,汽车类型,
日期时间,司机,codriver,地位); db.insert(DB_TABLE,KEY_STATUS,newContact);}私有静态ContentValues createContentValue(字符串vehicle_id,字符串汽车类型,
INT日期时间,串驱动器,串codriver,诠释状态)
{
ContentValues newContact =新ContentValues();
newContact.put(KEY_VEHICLE_ID,vehicle_id);
newContact.put(KEY_VEHICLE_TYPE,汽车类型);
newContact.put(KEY_DATETIME,日期时间);
newContact.put(KEY_DRIVER,驱动程序);
newContact.put(KEY_CO_DRIVER,codriver);
newContact.put(KEY_STATUS,地位); 返回newContact;
试着让你的SignalSetDBHelper类,如:
公共类SignalSetDBHelper扩展SQLiteOpenHelper { 私有静态最后弦乐DATABASE_NAME =DB;
私有静态最终诠释DATABASE_VERSION = 1;
私有静态最后弦乐INSPECTION_CREATE =创建表检查(
+_id整数主键自动增量
+vehicle_id字符串不为空,
+汽车类型的字符串不为空,
+日期时间整数不为空,
+驱动程序字符串不为空,
+codriver字符串
+状态整数非空
+);; 公共SignalSetDBHelper(上下文的背景下){
超(背景下,DATABASE_NAME,空,DATABASE_VERSION);
}
@覆盖
公共无效的onCreate(SQLiteDatabase DB){ database.execSQL(INSPECTION_CREATE);
//为其他两个表做同样的
}
公共无效onUpgrade(SQLiteDatabase数据库,诠释oldVersion,诠释静态网页){ database.execSQL(DROP TABLE IF EXISTS检查);
//为其他两个表做同样的
的onCreate(数据库);
}
}
而在SignalSetDBHelper类的code,在onUpgrade方法,未包括InspectionsTable.onUpgrade(数据库,oldVersion,静态网页);和所有报表后,您还应该添加的onCreate(数据库); there.So尝试添加这对您现有的code和看到的结果是任何成功,你会得到!
I am trying to insert data into a table that is part of a larger project. I am getting the error above and cannot figure out how to create the table. The code that created the table is below and the tables name is inspections. So I very confused
here is the logcat info
02-27 18:38:45.956: I/Database(3559): sqlite returned: error code = 1, msg = no such table: inspections
02-27 18:38:45.967: E/Database(3559): Error inserting co_driver= driver=ewrre vehicle_id=ET 432 status=1 date_time=40 vehicle_type=truck
02-27 18:38:45.967: E/Database(3559): android.database.sqlite.SQLiteException: no such table: inspections: , while compiling: INSERT INTO inspections(co_driver, driver, vehicle_id, status, date_time, vehicle_type) VALUES(?, ?, ?, ?, ?, ?);
02-27 18:38:45.967: E/Database(3559): at android.view.View.performClick(View.java:2408)
Here is the code that creates the table
private static final String DATABASE_CREATE = "create table inspections ("
+ "_id integer primary key autoincrement, "
+ "vehicle_id string not null, "
+ "vehicle_type string not null, "
+ "datetime integer not null, "
+ "driver string not null, "
+ "codriver string , "
+ "status integer not null "
+ ");";
public static void onCreate(SQLiteDatabase database) {
database.execSQL(DATABASE_CREATE);
}
public static void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
Log.w(InspectionsTable.class.getName(), "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data");
database.execSQL("DROP TABLE IF EXISTS inspections");
onCreate(database);
}
This is the DBhelper class
public class SignalSetDBHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "db";
private static final int DATABASE_VERSION = 1;
public SignalSetDBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
// Method is called during creation of the database
@Override
public void onCreate(SQLiteDatabase db) {
CurrentStateTable.onCreate(db);
HoursOfServiceTable.onCreate(db);
InspectionsTable.onCreate(db);
}
// Method is called during an upgrade of the database,
// e.g. if you increase the database version
@Override
public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
CurrentStateTable.onUpgrade(database, oldVersion, newVersion);
HoursOfServiceTable.onUpgrade(database, oldVersion, newVersion);
}
}
This is the adapter class
public class InspectionDBAdapter {
private static final String KEY_ROWID ="_id";
private static final String KEY_VEHICLE_ID="vehicle_id";
private static final String KEY_VEHICLE_TYPE="vehicle_type";
private static final String KEY_DATETIME="date_time";
private static final String KEY_DRIVER="driver";
private static final String KEY_CO_DRIVER="co_driver";
private static final String KEY_STATUS="status";
private static final String DB_TABLE="inspections";
private Context context;
private SQLiteDatabase db;
private SignalSetDBHelper dbHelper;
public InspectionDBAdapter(Context context) {
this.context = context;
}
public InspectionDBAdapter open() throws SQLException {
dbHelper = new SignalSetDBHelper(context);
db = dbHelper.getWritableDatabase();
return this;
}
public void close() {
dbHelper.close();
}
public void insertInspection( String vehicle_id, String vehicle_type,
int datetime, String driver, String codriver, int status)
{
ContentValues newContact= createContentValue(vehicle_id, vehicle_type,
datetime, driver, codriver, status);
db.insert(DB_TABLE, KEY_STATUS, newContact);
}
private static ContentValues createContentValue(String vehicle_id, String vehicle_type,
int datetime, String driver, String codriver, int status)
{
ContentValues newContact= new ContentValues();
newContact.put(KEY_VEHICLE_ID , vehicle_id);
newContact.put(KEY_VEHICLE_TYPE , vehicle_type);
newContact.put(KEY_DATETIME , datetime);
newContact.put(KEY_DRIVER , driver);
newContact.put(KEY_CO_DRIVER , codriver);
newContact.put(KEY_STATUS , status);
return newContact;
Try making your SignalSetDBHelper class like:
public class SignalSetDBHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "db";
private static final int DATABASE_VERSION = 1;
private static final String INSPECTION_CREATE = "create table inspections ("
+ "_id integer primary key autoincrement, "
+ "vehicle_id string not null, "
+ "vehicle_type string not null, "
+ "datetime integer not null, "
+ "driver string not null, "
+ "codriver string , "
+ "status integer not null "
+ ");";
public SignalSetDBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
database.execSQL(INSPECTION_CREATE);
//do same for other two tables
}
public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
database.execSQL("DROP TABLE IF EXISTS inspections");
// do same for other two tables
onCreate(database);
}
}
And in your code of SignalSetDBHelper class,in onUpgrade method,you didn't include InspectionsTable.onUpgrade(database, oldVersion, newVersion); and after all statements,you should also add onCreate(database); there.So try adding this to your existing code and see the result for any success you would get!
这篇关于数据库(3300):sqlite的返回:错误code = 1,味精=没有这样的表:但表名是检验?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!