sqlitedatabase.Intert()和sqlitedatabase.execsql(“插入...”
我正在Java中的Android应用程序。在我的应用程序中,我需要在数据库中存储一个地址。我的地址存储在名为“ Adresse”的表中。该表的定义如下:
CREATE TABLE "adresse" (
"numero_rue" TEXT,
"type_voie" TEXT,
"voie" TEXT,
"code_postal" TEXT,
"ville" TEXT
);
我尝试通过两种不同的方法在我的表中插入一个地址:
public void setAdresse(String numRue, String typeVoie, String voie, String codePostal, String ville) {
// First one
ContentValues values = new ContentValues();
values.put("numero_rue" , numRue );
values.put("type_voie" , typeVoie );
values.put("voie" , voie );
values.put("code_postal", codePostal);
values.put("ville" , ville );
db.insert("adresse", null, values);
// Second one
String req = "insert into adresse (numero_rue, type_voie, voie, code_postal, ville) values";
req += "(\"" + numRue + "\",\"" + typeVoie + "\",\"" + voie + "\",\"" + codePostal + "\",\"" + ville + "\")";
db.execSQL(req);
}
我在此方法中调用setadresse(...)
方法:
public void valider(View paramView) {
[ data recovery without problems ]
final DatabaseAccess db = DatabaseAccess.getInstance(this.getApplicationContext());
db.open();
db.setAdresse(numRue, typeVoie, voie, codePostal, ville);
db.close();
}
我向您展示我的构造函数,我的open()
, close()和getInstance()
方法:
private DatabaseAccess(Context context) { this.openHelper = new DatabaseOpenHelper(context); }
public static DatabaseAccess getInstance(Context context) {
if( instance == null ) instance = new DatabaseAccess(context);
return instance;
}
public void open() { this.db = openHelper.getWritableDatabase(); }
public void close() { if( this.db != null ) this.db.close(); }
我的问题是将数据插入表不起作用。我在日志中找不到错误,并且我的应用程序不会崩溃。我认为这不是代码错误,有人告诉我它可以链接到我的“驱动程序利用率”。
I'm working on an Android application in Java. In my application I need, among other things, to store an address in a database. My address is stored in a table named "adresse". This table is defined as below:
CREATE TABLE "adresse" (
"numero_rue" TEXT,
"type_voie" TEXT,
"voie" TEXT,
"code_postal" TEXT,
"ville" TEXT
);
I've tried to insert an address in my table by two different methods:
public void setAdresse(String numRue, String typeVoie, String voie, String codePostal, String ville) {
// First one
ContentValues values = new ContentValues();
values.put("numero_rue" , numRue );
values.put("type_voie" , typeVoie );
values.put("voie" , voie );
values.put("code_postal", codePostal);
values.put("ville" , ville );
db.insert("adresse", null, values);
// Second one
String req = "insert into adresse (numero_rue, type_voie, voie, code_postal, ville) values";
req += "(\"" + numRue + "\",\"" + typeVoie + "\",\"" + voie + "\",\"" + codePostal + "\",\"" + ville + "\")";
db.execSQL(req);
}
I call the setAdresse(...)
method in this method:
public void valider(View paramView) {
[ data recovery without problems ]
final DatabaseAccess db = DatabaseAccess.getInstance(this.getApplicationContext());
db.open();
db.setAdresse(numRue, typeVoie, voie, codePostal, ville);
db.close();
}
I show you my constructor, my open()
, close()
and getInstance()
methods:
private DatabaseAccess(Context context) { this.openHelper = new DatabaseOpenHelper(context); }
public static DatabaseAccess getInstance(Context context) {
if( instance == null ) instance = new DatabaseAccess(context);
return instance;
}
public void open() { this.db = openHelper.getWritableDatabase(); }
public void close() { if( this.db != null ) this.db.close(); }
My problem is that inserting the data into the table is not working. I don't find errors in the logs and my application does not crash. I don't think it is a code error and someone told me it could be linked to my "driver utilisation".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以检查此 link 。这是一个用于插入sqlite表中的github示例项目
can you check this link. It is a github sample project for inserting in sqlite table