- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的应用程序数据库中,我有 2 个表,一个名为“PLAYERS”,其中包含每个用户的数据,另一个名为“FRIENDSLIST”,旨在成为每个注册帐户的个人“ friend ”列表。我的应用程序中的流程如何进行是当玩家 (Joe) 注册用户名时,他的信息进入“PLAYERS”表,现在他可以进入我的 FindFriends Activity ,在应用程序中搜索他 friend 的用户名 (Bob),然后单击添加按钮。
friend (Bob) 然后被添加到“FRIENDSLIST”表中。当他进入 PlayAFriend Activity 时,将加载一个列表,显示他添加的“ friend ”。所有这一切都很好,直到我意识到当我登录时他 friend (Bob) 的一个帐户,该 friend 拥有与 (Joe) 相同的列表。
我知道我用来加载 (Joe) 的 friend 列表的光标与我用来加载 (Bob) 的 friend 列表的光标相同,所以我要问的问题是,
我如何让 Joe 和 Bob 拥有他们自己的个人好友列表?
我已经尝试在这个网站上搜索并使用谷歌搜索来寻找任何关于如何完成这个的例子,但我发现我没有找到关于这个主题的任何教程或帖子,即使这种做法在每个流行的应用程序。很抱歉发了这么长的帖子,我知道这不是一个简单的问题,所以我必须详细解释问题所在。
我正在发布我的 DBAdapter 类来展示我是如何制作它的,以及我的 PlayAFriend 类来展示我的 Cursor 和 ListView 的实际操作。
DBAdapter类
package com.fullfrontalgames.numberfighter;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DBAdapter {
static final String KEY_ROWID = "_id";
static final String KEY_USERNAME = "USERNAME";
static final String KEY_PASSWORD = "PASSWORD";
static final String KEY_EMAIL = "EMAIL";
static final String KEY_NUMBERINPUT = "NUMBERINPUT";
static final String KEY_SCORE = "SCORE";
static final String KEY_FRIENDS = "FRIENDS";
static final String TAG = "DBAdapter";
static final String DATABASE_NAME = "NFDatabase";
static final String DATABASE_TABLE1 = "PLAYERS";
static final String DATABASE_TABLE2 = "FRIENDSLIST";
static final int DATABASE_VERSION = 4;
static final String DATABASE_CREATE_TABLE1 = "create table PLAYERS ( _id integer primary key autoincrement, "
+ "USERNAME text not null unique,PASSWORD text not null,EMAIL text,NUMBERINPUT text,SCORE text);";
static final String DATBASE_CREATE_TABLE2 = "create table FRIENDSLIST (_id integer primary key autoincrement,"
+ "FRIENDS text not null,USERNAME text ,NUMBERINPUT text,SCORE text);";
final Context context;
DatabaseHelper DBHelper;
static SQLiteDatabase db;
public DBAdapter(Context ctx) {
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
private static class DatabaseHelper extends SQLiteOpenHelper {
public DatabaseHelper(Context context) {
// TODO Auto-generated constructor stub
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
try {
db.execSQL(DATABASE_CREATE_TABLE1);
db.execSQL(DATBASE_CREATE_TABLE2);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion
+ ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS PLAYERS");
db.execSQL("DROP TABLE IF EXISTS FRIENDSLIST");
onCreate(db);
}
}
public DBAdapter open() throws SQLiteException {
db = DBHelper.getWritableDatabase();
return this;
}
public void close() {
DBHelper.close();
}
// PLAYERS TABLE CRUD
public long insertPlayer(String Username, String Password, String Email) {
ContentValues initialValues = new ContentValues();
initialValues.put("USERNAME", Username);
initialValues.put("PASSWORD", Password);
initialValues.put("EMAIL", Email);
db.insert("PLAYERS", null, initialValues);
return db.insertWithOnConflict("PLAYERS", null, initialValues,
SQLiteDatabase.CONFLICT_IGNORE);
}
public boolean deletePlayer(long id) {
Log.d(TAG, "delete is working");
return db.delete("PLAYERS", KEY_ROWID + " = " + id, null) > 0;
}
public Cursor getAllPlayers() {
return db.query(false, "Players", new String[] {
"_id", "USERNAME", "PASSWORD", "EMAIL"
}, null, null, null, null, null, null);
}
public String getData() {
String[] columns = new String[] {
"_id", "USERNAME", "PASSWORD"
};
Cursor mCursor = db.query("PLAYERS", columns, null, null, null, null, null);
String result = "";
int iRow = mCursor.getColumnIndex(KEY_ROWID);
int iName = mCursor.getColumnIndex(KEY_USERNAME);
for (mCursor.moveToFirst(); !mCursor.isAfterLast(); mCursor.moveToNext()) {
result = mCursor.getString(iRow) + " " + mCursor.getString(iName) + "/n";
}
return result;
}
public Cursor getPlayer(int _id) throws SQLException {
Cursor mCursor = db.query(true, "PLAYERS", new String[] {
"_id", "USERNAME"
}, KEY_ROWID + " = " + "_id", null, null, null, null, null);
while (mCursor.moveToNext()) {
int id = mCursor.getInt(mCursor.getColumnIndex("_id"));
}
return mCursor;
}
public String getUsername(String Username) {
Cursor mCursor = db.query("Players", new String[] {
"USERNAME"
}, "USERNAME = ?", new String[] {
Username
}, null, null, null);
if (mCursor.moveToNext())
return mCursor.getString(0);
else
return "";
}
public String getSinlgeEntry(String Username) {
Cursor cursor = db.query("PLAYERS", null, " USERNAME=?", new String[] {
Username
}, null, null, null);
if (cursor.getCount() < 1) // UserName Not Exist
{
cursor.close();
return "NOT EXIST";
}
cursor.moveToFirst();
String password = cursor.getString(cursor.getColumnIndex("PASSWORD"));
cursor.close();
return password;
}
public boolean updatePlayer(long _id, String Username, String Password, String Email) {
ContentValues args = new ContentValues();
args.put("USERNAME", Username);
args.put("PASSWORD", Password);
args.put("EMAIL", Email);
return db.update("PLAYERS", args, KEY_ROWID + " = " + _id, null) > 0;
}
// FRIENDS TABLE CRUD
public void insertFriend(String Friend) {
ContentValues initialValues = new ContentValues();
initialValues.put("FRIENDS", Friend);
db.insert("FRIENDSLIST", null, initialValues);
}
public boolean deleteFriend() {
return db.delete("FRIENDSLIST", KEY_ROWID + " = " + "_id", null) > 0;
}
public Cursor getAllFriends() {
return db.query(false, "FRIENDSLIST", new String[] {
"_id", "FRIENDS"
}, null, null, null, null, null, null);
}
public Cursor getFriend(long rowid) throws SQLException {
Cursor mCursor = db.query(true, "FRIENDSLIST", new String[] {
"_id", "FRIENDS"
}, KEY_ROWID + " = " + "_id", null, null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
public boolean updateFriend(long _id, String Friends) {
ContentValues args = new ContentValues();
args.put("FRIENDS", Friends);
return db.update("FRIENDSLIST", args, KEY_ROWID + " = " + _id, null) > 0;
}
}
PlayAFriend 类
package com.fullfrontalgames.numberfighter;
import android.app.ListActivity;
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.TextView;
public class PlayAFriend extends ListActivity {
DBAdapter DBAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.playafriend);
final DBAdapter db = new DBAdapter(this);
DBAdapter = db.open();
getListView().setAdapter(new FriendsListAdapter(this, db.getAllFriends()));
}
private class FriendsListAdapter extends BaseAdapter implements OnClickListener, ListAdapter {
private Cursor fFriends;
private Context fContext;
public FriendsListAdapter(Context context, Cursor friends) {
// TODO Auto-generated constructor stub
fContext = context;
fFriends = friends;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return fFriends.getCount();
}
@Override
public FriendInfo getItem(int position) {
// TODO Auto-generated method stub
if (fFriends.moveToPosition(position)) {
String name = fFriends.getString(fFriends.getColumnIndex("FRIENDS"));
return new FriendInfo(name);
}
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
fFriends.moveToPosition(position);
return fFriends.getLong(fFriends.getColumnIndex("_id"));
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
convertView = LayoutInflater.from(fContext).inflate(R.layout.playafriendlistitems,
parent, false);
}
FriendInfo friendinfo = getItem(position);
TextView friendTV = ViewHolder.get(convertView, R.id.textview_friends);
Button playbutton = ViewHolder.get(convertView, R.id.playbutton, position);
playbutton.setOnClickListener(this);
friendTV.setText(friendinfo.getName());
return convertView;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
DBAdapter db = new DBAdapter(fContext);
db.open();
int position = (Integer)v.getTag();
fFriends.moveToPosition(position);
long id = fFriends.getLong(fFriends.getColumnIndex("_id"));
fFriends = db.getAllFriends();
db.close();
}
}
}
新的数据库适配器
package com.fullfrontalgames.numberfighter;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DBAdapter {
static final String KEY_ROWID = "_id";
static final String KEY_USERNAME = "USERNAME";
static final String KEY_PASSWORD = "PASSWORD";
static final String KEY_EMAIL = "EMAIL";
static final String KEY_NUMBERINPUT = "NUMBERINPUT";
static final String KEY_SCORE = "SCORE";
static final String KEY_FRIENDS = "FRIENDS";
static final String TAG = "DBAdapter";
static final String DATABASE_NAME = "NFDatabase";
static final String DATABASE_TABLE1 = "PLAYERS";
static final String DATABASE_TABLE2 = "FRIENDSLIST";
static final int DATABASE_VERSION = 9;
static final String DATABASE_CREATE_TABLE1 = "create table PLAYERS ( _id integer primary key autoincrement, "
+ "USERNAME text not null unique,PASSWORD text not null,EMAIL text,NUMBERINPUT text,SCORE text);";
static final String DATBASE_CREATE_TABLE2 = "create table FRIENDSLIST (_id integer primary key autoincrement,"
+ "player_id integer not null references PLAYERS(_id) on update cascade on delete cascade,"
+ "FRIENDS text ,NUMBERINPUT text,SCORE text);";
final Context context;
DatabaseHelper DBHelper;
static SQLiteDatabase db;
public DBAdapter(Context ctx) {
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
private static class DatabaseHelper extends SQLiteOpenHelper {
public DatabaseHelper(Context context) {
// TODO Auto-generated constructor stub
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
try {
db.execSQL(DATABASE_CREATE_TABLE1);
db.execSQL(DATBASE_CREATE_TABLE2);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion
+ ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS PLAYERS");
db.execSQL("DROP TABLE IF EXISTS FRIENDSLIST");
onCreate(db);
}
}
public DBAdapter open() throws SQLiteException {
db = DBHelper.getWritableDatabase();
db.execSQL("PRAGMA foreign_keys=ON;");
return this;
}
public void close() {
DBHelper.close();
}
// PLAYERS TABLE CRUD
public long insertPlayer(String Username, String Password, String Email) {
ContentValues initialValues = new ContentValues();
initialValues.put("USERNAME", Username);
initialValues.put("PASSWORD", Password);
initialValues.put("EMAIL", Email);
db.insert("PLAYERS", null, initialValues);
return db.insertWithOnConflict("PLAYERS", null, initialValues,
SQLiteDatabase.CONFLICT_IGNORE);
}
public boolean deletePlayer(long id) {
Log.d(TAG, "delete is working");
return db.delete("PLAYERS", KEY_ROWID + " = " + id, null) > 0;
}
public Cursor getAllPlayers() {
return db.query(false, "Players", new String[] {
"_id", "USERNAME", "PASSWORD", "EMAIL"
}, null, null, null, null, null, null);
}
public String getData() {
String[] columns = new String[] {
"_id", "USERNAME", "PASSWORD"
};
Cursor mCursor = db.query("PLAYERS", columns, null, null, null, null, null);
String result = "";
int iRow = mCursor.getColumnIndex(KEY_ROWID);
int iName = mCursor.getColumnIndex(KEY_USERNAME);
for (mCursor.moveToFirst(); !mCursor.isAfterLast(); mCursor.moveToNext()) {
result = mCursor.getString(iRow) + " " + mCursor.getString(iName) + "/n";
}
return result;
}
public Cursor getPlayer(int _id) throws SQLException {
Cursor mCursor = db.query(true, "PLAYERS", new String[] {
"_id", "USERNAME"
}, KEY_ROWID + " = " + "_id", null, null, null, null, null);
while (mCursor.moveToNext()) {
int id = mCursor.getInt(mCursor.getColumnIndex("_id"));
}
return mCursor;
}
public String getUsername(String Username) {
Cursor mCursor = db.query("Players", new String[] {
"USERNAME"
}, "USERNAME = ?", new String[] {
Username
}, null, null, null);
if (mCursor.moveToNext())
return mCursor.getString(0);
else
return "";
}
public String getSinlgeEntry(String Username) {
Cursor cursor = db.query("PLAYERS", null, " USERNAME=?", new String[] {
Username
}, null, null, null);
if (cursor.getCount() < 1) // UserName Not Exist
{
cursor.close();
return "NOT EXIST";
}
cursor.moveToFirst();
String password = cursor.getString(cursor.getColumnIndex("PASSWORD"));
cursor.close();
return password;
}
public boolean updatePlayer(long _id, String Username, String Password, String Email) {
ContentValues args = new ContentValues();
args.put("USERNAME", Username);
args.put("PASSWORD", Password);
args.put("EMAIL", Email);
return db.update("PLAYERS", args, KEY_ROWID + " = " + _id, null) > 0;
}
// FRIENDS TABLE CRUD
public void insertFriend(long playerId, String Friend) {
ContentValues initialValues = new ContentValues();
initialValues.put("player_id", playerId);
initialValues.put("FRIENDS", Friend);
db.insertWithOnConflict("FRIENDSLIST", null, initialValues, SQLiteDatabase.CONFLICT_IGNORE);
}
public boolean deleteFriend() {
return db.delete("FRIENDSLIST", KEY_ROWID + " = " + "_id", null) > 0;
}
public Cursor getAllFriends() {
return db.query(false, "FRIENDSLIST", new String[] {
"_id", "FRIENDS"
}, null, null, null, null, null, null);
}
public Cursor getFriend(long player_id) throws SQLException {
Cursor mCursor = db.query(true, "FRIENDSLIST", new String[] {
"_id", "FRIENDS"
}, "player_id" + " = " + "player_id", null, null, null, null, null);
// cursor from query is never null,
// should just check for if (cursor.moveToFirst()) in the calling
// activity
return mCursor;
}
public boolean updateFriend(long _id, String Friends) {
ContentValues args = new ContentValues();
args.put("FRIENDS", Friends);
return db.update("FRIENDSLIST", args, KEY_ROWID + " = " + _id, null) > 0;
}
public long getPlayerId(String Username) {
// TODO Auto-generated method stub
long id = 0;
Cursor c = db.query("PLAYERS", new String[] {
KEY_ROWID
}, KEY_USERNAME + "=?", new String[] {
Username
}, null, null, null);
if (c.moveToFirst()) {
id = c.getLong(0);
}
c.close();
return id;
}
}
New PlayAFriend
package com.fullfrontalgames.numberfighter;
import android.app.ListActivity;
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.TextView;
public class PlayAFriend extends ListActivity {
DBAdapter DBAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.playafriend);
final DBAdapter db = new DBAdapter(this);
DBAdapter = db.open();
long player_id = 0;
getListView().setAdapter(new FriendsListAdapter(this, db.getFriend(player_id)));
}
private class FriendsListAdapter extends BaseAdapter implements OnClickListener, ListAdapter {
private static final long player_id = 0;
private Cursor fFriends;
private Context fContext;
public FriendsListAdapter(Context context, Cursor friends) {
// TODO Auto-generated constructor stub
fContext = context;
fFriends = friends;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return fFriends.getCount();
}
@Override
public FriendInfo getItem(int position) {
// TODO Auto-generated method stub
if (fFriends.moveToPosition(position)) {
String name = fFriends.getString(fFriends.getColumnIndex("FRIENDS"));
return new FriendInfo(name);
}
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
fFriends.moveToPosition(position);
return fFriends.getLong(fFriends.getColumnIndex("_id"));
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
convertView = LayoutInflater.from(fContext).inflate(R.layout.playafriendlistitems,
parent, false);
}
FriendInfo friendinfo = getItem(position);
TextView friendTV = ViewHolder.get(convertView, R.id.textview_friends);
Button playbutton = ViewHolder.get(convertView, R.id.playbutton, position);
playbutton.setOnClickListener(this);
friendTV.setText(friendinfo.getName());
return convertView;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
DBAdapter db = new DBAdapter(fContext);
db.open();
int position = (Integer)v.getTag();
fFriends.moveToPosition(position);
long id = fFriends.getLong(fFriends.getColumnIndex("_id"));
fFriends = db.getFriend(id);
db.close();
}
}
}
找 friend Activity
package com.fullfrontalgames.numberfighter;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;
public class Findfriends extends Activity {
DBAdapter db;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.findfriends);
final EditText sbar = (EditText)findViewById(R.id.PlayerSeachBar);
Button search = (Button)findViewById(R.id.Search);
Button Add = (Button)findViewById(R.id.Add);
final TextView ResultText = (TextView)findViewById(R.id.ResultTextView);
final FrameLayout ResultFrame = (FrameLayout)findViewById(R.id.ResultFrameLayout);
ResultFrame.setVisibility(View.GONE);
final DBAdapter db = new DBAdapter(this);
db.open();
search.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String Username = sbar.getText().toString();
String foundplayer = db.getUsername(Username);
if (Username.equals(foundplayer)) {
ResultFrame.setVisibility(View.VISIBLE);
ResultText.setText(foundplayer);
Toast.makeText(getApplicationContext(), "Player Found", Toast.LENGTH_LONG)
.show();
} else {
Toast.makeText(getApplicationContext(), "Username Not Found", Toast.LENGTH_LONG)
.show();
}
}
});
Add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String Friends = sbar.getText().toString();
long playerId = db.getPlayerId(Friends);
db.insertFriend(playerId, Friends);
Toast.makeText(getApplicationContext(), "Player Has Been Added", Toast.LENGTH_LONG)
.show();
}
});
}
}
日志猫
04-22 21:11:37.834: E/SQLiteDatabase(15862): Error inserting player_id=0 FRIENDS=null
04-22 21:11:37.834: E/SQLiteDatabase(15862): android.database.sqlite.SQLiteConstraintException: foreign key constraint failed (code 19)
04-22 21:11:37.834: E/SQLiteDatabase(15862): at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
04-22 21:11:37.834: E/SQLiteDatabase(15862): at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:775)
最佳答案
改变你的表格FRIENDSLIST
static final String DATBASE_CREATE_TABLE2 =
"create table FRIENDSLIST (_id integer primary key autoincrement,"
+ "player_id integer not null references PLAYERS("_id") on update cascade on delete cascade,"
+ "FRIENDS text not null,USERNAME text ,NUMBERINPUT text,SCORE text);";
当你插入
public void insertFriend(long playerId, String Friend) {
ContentValues initialValues = new ContentValues();
initialValues.put("player_id", playerId);
initialValues.put("FRIENDS", Friend);
db.insertWithOnConflict("FRIENDSLIST", null, initialValues, SQLiteDatabase.CONFLICT_IGNORE);
}
结交 friend
public Cursor getFriend(long rowid) throws SQLException {
Cursor mCursor = db.query(true, "FRIENDSLIST", new String[] {
"_id", "FRIENDS"
}, player_id + " = " + "rowid", null, null, null, null, null);
// cursor from query is never null,
// should just check for if (cursor.moveToFirst()) in the calling activity
return mCursor;
}
在数据库打开方法中添加
public DBAdapter open() throws SQLiteException {
db = DBHelper.getWritableDatabase();
db.execSQL("PRAGMA foreign_keys=ON;");
return this;
}
关于android - SQLitedatabase 每个用户名都有相同的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16158824/
表字段: _id, street, house_nr 查询: mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_STREET_NAME,
我在 Android 中查询 SQLITE 数据库时遇到问题。我有一个名为“重置”的表,其中包含一些值。目前我只有一篇文章。 reset_timestamp | interval 1479442048
您好,我想知道在 Android 上哪种方法更快。 我有一个处理数千行的循环,我认为 SQLiteDatabase.insert() 方法会影响性能。 在插入方法中,我放置了一个带有 contentv
我有 editText1、editText2 和 EditText3 .用户需要在此区域写入个人信息。当他们按下保存按钮时, editText1、editText2 和 EditText3 必须保存。
我总是收到此错误。我的数据库是我自己创建的。我的意思是,我不是用代码创建它的。它从 Assets 文件夹创建它,如果我通过手机上的 Sqlite 阅读器应用程序打开它,它会完美地显示表格和数据。但是我
在我的应用程序数据库中,我有 2 个表,一个名为“PLAYERS”,其中包含每个用户的数据,另一个名为“FRIENDSLIST”,旨在成为每个注册帐户的个人“ friend ”列表。我的应用程序中的流
我想知道如何使用具有 where 子句和 like 属性的查询方法。基本上我想要的是选择所有列,其中 C_NAME 列是 LIKE keyWord。 我已经试过了,但它不起作用: cursor = d
我想打开一个包含所有短信和彩信的数据库。我想这样做是因为我需要进行原始查询,所以我需要让它工作。我正在尝试这样做: try{ SQLiteDatabase sqLiteDataba
在我的 SQLiteOpenHelper 类中寻址我的数据库时,我收到“没有这样的表”错误,即使调用了 onCreate 方法并且我在该方法中创建了表结构。 public class BVCDbHel
我试图在 SQLiteDatabase 中存储一些信息。当我调用方法 insert 时,它返回 -1。所以发生了错误,但我无法弄清楚哪里出了问题。 代码如下: public class SQLiteH
我有一个扩展 SQLiteOpenHelper 的类和一个声明为的数据库: @Override public void onCreate(SQLiteDatabase db) { db.exe
我正在尝试研究并制作一个简单的数据库,该数据库创建一个只有一行的表。当我使用 SQLiteHelper 的“update()”方法时,我第一次看到它有效。但是,当我尝试使用 SQL 命令“UPDATE
每当我使用数据库时,我都会创建一个新的 SQLOpenHelper 实例。 我有一个屏幕 A,它有一个在 onResume () 中使用 readableDatabase () 的方法。在屏幕 B 中
我正在实现“添加到 Collection 夹”功能。用户应该能够将数据添加到数据库的位置。 DatabaseHandler 正在运行,我已经创建了一个类来处理 get/set 方法。 我可以轻松地将数
我正在编写一个显示有趣事实(及其来源)的应用程序。用户可以一个一个地浏览事实。 这是我想到的设计: 在 SQLiteDatabase 中创建一个表,其中一个文本列存储有趣的事实,第二个列存储它的来源。
我试图存储一个非常大的数字,它大于 INTEGER 和 REAL 字段类型可以容纳的 8 个字节。我需要能够返回此字段中包含小于或大于我指定的另一个大数字的数字的行。我不知道该怎么做。似乎我唯一的选择
已编辑: 是的,SQLite doesn't support嵌套事务,但是 docs声明 SQLiteDatabase 确实如此。 情况 我有一个包含交易的方法,我需要从另一个交易中调用这个方法。 此
有没有一种直接的方法来查询 SQLiteDatabase 的选择参数不是 String 类型? 特别是:如果 arg 是 byte[] 类型? 我能找到的最接近的东西是 SQLiteDatabase.
我试图让 db.update 用新值更新我的数据库中的一行,但它似乎没有保存。我查看了语法,但似乎无法保存数据。插入功能有效但不更新。任何帮助,将不胜感激。下面是我的数据类,它使用 DbHelper
我正在尝试从数据库中删除一些内容然后插入一个新值。我对数据库知之甚少,所以希望得到有关这里出了什么问题的建议。 我不断收到以下错误: Caused by: java.lang.IllegalState
我是一名优秀的程序员,十分优秀!