gpt4 book ai didi

安卓 :SQLite insert in Database

转载 作者:搜寻专家 更新时间:2023-11-01 07:59:32 25 4
gpt4 key购买 nike

<分区>

我无法插入数据库,这段代码有什么问题。在此先感谢。

public long insertGrille(Grille grille) {
ContentValues values = new ContentValues();
//values.put(COL_ID, grille.getId());
values.put(COL_X, grille.getxCoordinate());
Log.i("COL_X, grille.getxCoordinate()", grille.getxCoordinate() + "");
values.put(COL_Y, grille.getyCoordinate());
values.put(COL_SSID, grille.getSsid());
values.put(COL_RSSI, grille.getrssi());
Log.i("insertion", values + "");
Log.i("insertion", grille.getxCoordinate() + "");
Log.i("insertion", bdd.insert(TABLE_RSSI, null, values) + "");
return bdd.insert(TABLE_RSSI, null, values);
}

创建数据库:

public class MaBaseSQLite extends SQLiteOpenHelper{

private static final String TABLE_RSSI = "table_rssi";
private static final String COL_ID = "ID";
private static final String COL_X = "Xcoordinate ";
private static final String COL_Y = "Ycoordinate ";
private static final String COL_SSID = "SSID";
private static final String COL_RSSI = "RSSI";

private static final String CREATE_BDD = " CREATE TABLE " + " TABLE_RSSI " + " (" + COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COL_X + " TEXT NOT NULL, " + COL_Y + " TEXT NOT NULL, " + COL_SSID + " TEXT NOT NULL, " + COL_RSSI + " TEXT NOT NULL);";


public MaBaseSQLite(Context context, String name, CursorFactory factory,
int version) {
super(context, name, factory, version);
// TODO Auto-generated constructor stub
}


@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL(CREATE_BDD);
Log.i("base créee","base créee");

}


@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE" + TABLE_RSSI + ";");
onCreate(db);
}

}编辑

  case R.id.button1:
Grille grille = new Grille(xCoordinate, yCoordinate, ssid, rssi);

//livre.setIsbn(isbn);
//livre.setTitre(titre);
GrillePuissanceBDD liv = new GrillePuissanceBDD(getApplicationContext());
liv.open();
liv.insertGrille(grille);
Log.i("grille***", grille + "");
Log.i("getxCoordinate***", grille.getxCoordinate() + "");
Grille livreFromBdd = liv.getGrilleWithTitre(grille.getxCoordinate());
Log.i("livreFromBdd", livreFromBdd + "");
if (livreFromBdd != null) {
Toast.makeText(this, livreFromBdd.toString(), Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Prbleme", Toast.LENGTH_LONG).show();
}
liv.close();
break;

我没有收到错误,这是堆栈跟踪:

    04-16 04:47:34.700: I/creation base(9205): creation
04-16 04:47:34.860: I/COL_X, grille.getxCoordinate()(9205): xCoordinate
04-16 04:47:34.880: I/insertion(9205): Ycoordinate=yCoordinate RSSI=ssid Xcoordinate =xCoordinate SSID=rssi
04-16 04:47:34.880: I/insertion(9205): xCoordinate
04-16 04:47:34.990: I/insertion(9205): 29
04-16 04:47:35.020: I/grille***(9205): ID :0
04-16 04:47:35.020: I/grille***(9205): SSID : rssi
04-16 04:47:35.020: I/grille***(9205): X : xCoordinate
04-16 04:47:35.020: I/grille***(9205): Y : yCoordinate
04-16 04:47:35.020: I/grille***(9205): Puissance : ssid
04-16 04:47:35.020: I/getxCoordinate***(9205): xCoordinate
04-16 04:47:35.040: I/Cursor c(9205): android.database.sqlite.SQLiteCursor@41757ca8
04-16 04:47:35.110: I/c.getCount()(9205): 0
04-16 04:47:35.110: I/Cursor(9205): null
04-16 04:47:35.140: I/cursorTest(9205): ID :1
04-16 04:47:35.140: I/cursorTest(9205): SSID :
04-16 04:47:35.140: I/cursorTest(9205): X :
04-16 04:47:35.140: I/cursorTest(9205): Y :
04-16 04:47:35.140: I/cursorTest(9205): Puissance :
04-16 04:47:35.150: I/c.getCount()(9205): 0
04-16 04:47:35.150: I/livreFromBdd(9205): null

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com