Tag: android sqlite

getReadableDatabase()上的NullPointerException

我在课堂上有这种方法(非活动) – public boolean usernameChk(String usrname) { String usrnmQuery = “SELECT * FROM ” + TABLE_ACCOUNTS + ” WHERE username = ‘” + usrname + “‘”; SQLiteDatabase db = this.getReadableDatabase(); //NullPointerException on line above Cursor cursor = db.rawQuery(usrnmQuery, null); cursor.close(); if (cursor.getCount() <= 0) { return false; } else { return true; } } 但是我在SQLiteDatabase […]

SQLite查询:获取一行的所有列(android)?

这是架构: SQL查询是:SELECT * from unjdat,其中col_1 =“myWord”; 即,我想显示col_1为myWord的行的所有列。 int i; String temp; words = new ArrayList(); Cursor wordsCursor = database.rawQuery(“select * from unjdat where col_1 = \”apple\” “, null); //myWord is “apple” here if (wordsCursor != null) wordsCursor.moveToFirst(); if (!wordsCursor.isAfterLast()) { do { for (i = 0; i < 11; i++) { temp = wordsCursor.getString(i); words.add(temp); […]

Android:FragmentPagerAdapter不保存Fragment的状态?

我有FragmentPagerAdapter的问题。 我无法保存Fragment的状态,然后在Fragment中有视图。 每当我使用向左和向右滑动时,通过覆盖扩展FragmentPagerAdapter的静态类中的方法getItem(int position)来重新创建Fragment。 public static class GraphicsCollectionPagerAdapter extends FragmentPagerAdapter { final int NUM_ITEMS = 3; // number of tabs public GraphicsCollectionPagerAdapter(FragmentManager fm) { super(fm); fragmentList = new AnalyzeFragmentPageListWithDate(); fragment1 = new AnalyzeFragmentPage1(); fragment2 = new AnalyzeFragmentPage2(); } @Override public Fragment getItem(int position) { //Log.i(TAG, “getItem() -> New fragment at position ” + position); switch […]

将设备数据与Web服务器同步

我的应用程序中有数据,必须根据网络可用性在服务器上更新。 我使用sqlite将这些数据存储在android上的本地数据库中。 目前的想法是: 应将数据插入本地sqlite数据库 插入数据后,服务应该等待它检查网络可用性并将其发送到服务器并等待成功响应。 如果从服务器收到响应true,它应该更新该sqlite行的同步状态并移动到下一行以发送数据。 我想找出将此数据排队以将其发送到服务器的最佳方法,此外,当网络不可用时,此队列应停止向服务器发送数据。 由于java中有许多队列可用,因此最好保存这些数据。 由于数据可以增长到任何无限大小。 这就像生产者 – 消费者问题,但解决它的最有效方法是什么。 提前致谢。

Sqlite数据库更新了一行android

我正在开发一个Android应用程序,我需要根据某个where子句更新表中的列。这是下面的代码, public void updatethekeyofweeklycolumn(String profilename, String keystemp) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(Profile_keysofweekly, keystemp); db.update(TABLE_PROFILE_SETTINGS_FOR_WEEKLY, values,Profile_Name_for_weekly +” = “+profilename, null); } 上面的代码在where子句为null时工作正常,但是它设置了一个与whereclause关闭的力。 我的查询错了吗?

IntentService冻结了我的应用程序UI

在我的应用程序中,我使用Intentservice从服务器获取数据并将获取的数据存储到本地sqlite db。 我正在使用5个IntentService来获取和填充五个表。 每个Intent Service的数据最多可达300行。 我该怎么办? IntentService代码: public class SendBpRecordServer extends IntentService { DbHelper dbHelper; public static final String TAG=”BP Service”; public JSONObject finalData; public SendBpRecordServer() { super(“BP”); dbHelper=new DbHelper(this); Log.i(“In Constructor”,TAG); } @Override protected void onHandleIntent(Intent intent) { String recName=intent.getStringExtra(“nameTag”); if (recName.equals(“fetch”)) { Log.i(“Send Data”,”Yes”); fetchDatFromServer(); ResultReceiver resultReceiver=intent.getParcelableExtra(“receiverTagBP”); Log.d(“BP Reseult “,resultReceiver.toString()); Bundle bun= new […]

Android – SQLite – 选择BETWEEN Date1和Date2

Mac OS-X Android的 Eclipse与ADT SQLite的 我是创建Android应用程序的新手,我对此进行了大量研究,但我无处可去。 我需要查询我的SQLite数据库以返回2个日期之间的所有行。 到目前为止,我从我的研究中学到的是Androids SQLite数据库中没有DateTime列,我必须将其保存为文本列。 但我认为问题在于尝试比较字符串,但我无法找到解决方法。 这是我的代码: DB = currentContext.openOrCreateDatabase(DBName, 0, null); DB.execSQL(“CREATE TABLE IF NOT EXISTS ” + tableName + ” (ID INTEGER PRIMARY KEY AUTOINCREMENT, Date VARCHAR(40), Hours INT(3));”); 我没有收到任何错误,但我没有从RawQuery返回任何结果。 这是我的代码: Cursor c = newDB.rawQuery(“select ID, Date, Hours from ” + tableName + ” where Date BETWEEN ‘” + […]

当通过首次打开数据库触发OnCreate时,无法从SQLIte Helper Oncreate打开SQLite数据库

当mainactivity在安装应用程序后第一次尝试打开数据库时,会触发SQLiteHelper Oncreate方法(正如人们所期望的那样)。 我想在OnCreate中创建数据表之后填充数据库,但这样做需要我在我的内容创建者类(从OnCreate调用)中再次打开数据库。 当应用程序尝试在内容创建者类中打开数据库时,应用程序崩溃 基本上我是在创建数据库时尝试填充数据库,但显然不是正确的方式。 来自SQLiteHelper类 : … @Override public void onCreate(SQLiteDatabase db) { db.execSQL(SQL_CREATE_TABLE); //sql string to create the table dbContents.baseContents(sqcontext); } 来自内容创建者类 : public class dbContents { public static void baseContents(Context context) { dbDataSource ds = new dbDataSource(context); ds.open(); … 从dbDataSource类 : public dbDataSource(Context context) { dbHelper = new MySQLiteHelper(context); DatabaseVersion = dbHelper.DatabaseVersion; […]