- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试开发一项服务,该服务每 2 分钟连续检查一次 sqlite 数据库以获取匹配记录。我发现了以下 2 个错误:
日志错误:
couldn't read row 0 col -1 from cursorwindow
下面提到了我的java文件
**myseervice.java**
package com.blundell.tut.ui.phone;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import com.blundell.tut.R;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
public class MyService extends Service {
/*---String result;
String oid1,operatorid1;*/
DatabaseHandler db = new DatabaseHandler(this);
public String tableName = db.TABLE_CONTACTS;
public String task_name = db.KEY_TASK;
public String dt = db.KEY_DATETIME;
String tname, dt1;
NotificationManager nm;
static final int uniqueID = 1394885;
ResponseHandler<String> responseHandler;
SQLiteDatabase dbobject;
Cursor c;
Context context, ctx1;
// flag for Internet connection status
// -- Boolean isInternetPresent = false;
// Connection detector class
// ---- ConnectionDetector cd;
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public void onStart(Intent intent, int startId) {
final Calendar c1 = Calendar.getInstance();
int hour = c1.get(Calendar.HOUR_OF_DAY);
int minutes = c1.get(Calendar.MINUTE);
int day = c1.get(Calendar.DAY_OF_MONTH);
int month = c1.get(Calendar.MONTH);
int year1 = c1.get(Calendar.YEAR);
String combine = String.valueOf(day).trim() + ":"
+ String.valueOf(month + 1).trim() + ":"
+ String.valueOf(year1).trim() + String.valueOf(hour) + ":"
+ String.valueOf(minutes);
String combine2 = String.valueOf(day).trim() + ":"
+ String.valueOf(month + 1).trim() + ":"
+ String.valueOf(year1).trim() + String.valueOf(hour) + ":"
+ String.valueOf(minutes - 1);
Log.w("trace", "date " + combine);
Log.w("trace", "date " + combine2);
// dbobject=this.openOrCreateDatabase("engdb.db",SQLiteDatabase.CREATE_IF_NECESSARY,null);
MainActivity act = new MainActivity();
dbobject = act.getInstance().openOrCreateDatabase("contactsManager",
SQLiteDatabase.CREATE_IF_NECESSARY, null);
// setDatabase(dbobject);
// String create_table
// ="create table if not exists contact(_id integer primary key autoincrement,"
// +
// " Day text null, Month text null,Year text null, Hour text null, Minutes text )";
// dbobject.execSQL(create_table);
String q = "SELECT task_name FROM contacts WHERE date_time='" + combine
+ "'";
c = dbobject.rawQuery(q, null);
System.out.print("totle record" + c.getCount());
if (c.moveToFirst()) {
for (int i = 0; i <= c.getCount(); i++) {
tname = c.getString(c.getColumnIndex("task_name"));
dt1 = c.getString(c.getColumnIndex("date_time"));
c.moveToNext();
}
c.close();
}
// if (c!=null) {
// do {
// // Contact contact = new Contact();
// /*
// * int id1=Integer.parseInt(c.getString(0)); String tname =
// * c.getString(1); String dt1 = c.getString(2);
// */// Adding contact to list
// // contactList.add(contact);
// tname = c.getString(c.getColumnIndex("task_name"));
// dt1 = c.getString(c.getColumnIndex("date_time"));
//
// } while (c.moveToNext());
// }
/*
* c.moveToNext();
*
* String tname =c.getString(c.getColumnIndex("task_name")); String dt1
* = c.getString(c.getColumnIndex("date_time"));
*/
// Toast.makeText(getApplicationContext(), "Service method is called",
// 1000).show();
Log.w("trace", "alarm has been fired " + c.getCount() + " " + tname
+ " " + dt1);
// c.close();
// ---- creating connection detector class instance
// cd = new ConnectionDetector(getApplicationContext());
// get Internet status
// ---- isInternetPresent = cd.isConnectingToInternet();
// check for Internet status
/*
* if (isInternetPresent) {
*/nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.cancel(uniqueID);
/*
* //open sqlite database here... localdatabase =
* context.openOrCreateDatabase("engdb.db",
* SQLiteDatabase.CREATE_IF_NECESSARY, null);
* setDatabase(localdatabase); String create_table =
* "create table if not exists contact((_id integer primary key autoincrement,"
* + " Day text not null, Month text not null,Year text)";
* localdatabase.execSQL(create_table);
*/
/*
* FileInputStream fin1; try { fin1 =openFileInput("op_id.txt");
* InputStreamReader isr1 = new InputStreamReader(fin1); char[]
* inputBuffer1 = new char[100]; String s1=""; int charRead1;
* while((charRead1 = isr1.read(inputBuffer1))>0) { String readString1
* =String.copyValueOf(inputBuffer1,0,charRead1); s1 += readString1;
* inputBuffer1=new char[100]; oid1=(s1); operatorid1=oid1;
* //Toast.makeText(getApplicationContext(), "in service."+operatorid1,
* 1000).show(); } }
*/
/*
* catch (FileNotFoundException e) { e.printStackTrace(); } catch
* (IOException e) { e.printStackTrace(); }
*/
/*
* try { ArrayList<NameValuePair> myForm=new
* ArrayList<NameValuePair>(1); myForm.add(new
* BasicNameValuePair("oid",operatorid1)); MyConnection mycon = new
* MyConnection(); String url= mycon.myurl(); HttpClient client = new
* DefaultHttpClient(); //ticket_check_service.php HttpPost postdata =
* new HttpPost(url+"op_ticket_check_service.php"); responseHandler =
* new BasicResponseHandler(); postdata.setEntity(new
* UrlEncodedFormEntity(myForm)); result = client.execute(postdata,
* responseHandler); } catch (ClientProtocolException e) {
* e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
*/
/*
* if(result.equals("0")==true) {
* //Toast.makeText(getApplicationContext(), "Sorry try again"+result,
* 1500).show(); } else { // Toast.makeText(getApplicationContext(),
* " Welcome Client "+result, 1500).show(); String str1 =
* result.substring(result.indexOf("T"),result.indexOf("T")+7); Intent
* myintent= new Intent(this,Ticket_List.class);
* myintent.putExtra("notift", "ticketnotif");
* myintent.putExtra("ticketid", str1); PendingIntent
* pi=PendingIntent.getActivity(getApplicationContext( ),0, myintent,
* 0); String body="Client Response for above Ticket id."; String title
* =result; Notification n= new
* Notification(R.drawable.notif_logo,body,System.currentTimeMillis());
* n.setLatestEventInfo(this,title, body,pi); n.defaults =
* Notification.DEFAULT_ALL; nm.notify(uniqueID,n);
*
* }
*/
/*
*
* Intent myintent= new Intent(this,SecondActivity.class); PendingIntent
* pi=PendingIntent.getActivity(getApplicationContext( ),0, myintent,
* 0); String body="Client Response for above Ticket id."; String title
* ="result"; Notification n= new
* Notification(R.drawable.nfm,body,System.currentTimeMillis());
* n.setLatestEventInfo(this,title, body,pi); n.defaults =
* Notification.DEFAULT_ALL; nm.notify(uniqueID,n);
*
* super.onStart(intent, startId);
*/
}
public void setDatabase(SQLiteDatabase db) {
this.dbobject = db;
}
}// end of IF condition
// end of start method
****database handler.java****
package com.blundell.tut.ui.phone;
import java.util.ArrayList;
import java.util.List;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DatabaseHandler extends SQLiteOpenHelper {
// All Static variables
// Database Version
public static final int DATABASE_VERSION = 1;
// Database Name
public static final String DATABASE_NAME = "contactsManager";
// Contacts table name
public static final String TABLE_CONTACTS = "contacts";
// Contacts Table Columns names
public static final String KEY_ID = "id";
public static final String KEY_TASK = "task_name";
public static final String KEY_DATETIME = "date_time";
Context ctx;
public List<Contact> contactList = new ArrayList<Contact>();
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
ctx = context;
}
// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "("
+ KEY_ID + " INTEGER PRIMARY KEY," + KEY_TASK + " TEXT,"
+ KEY_DATETIME + " TEXT" + ")";
db.execSQL(CREATE_CONTACTS_TABLE);
}
// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS);
// Create tables again
onCreate(db);
}
/**
* All CRUD(Create, Read, Update, Delete) Operations
*/
// Adding new contact
public void addContact(Contact contact) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_TASK, contact.getName()); // Contact Name
values.put(KEY_DATETIME, contact.getPhoneNumber()); // Contact Phone
// Inserting Row
db.insert(TABLE_CONTACTS, null, values);
db.close(); // Closing database connection
}
// Getting single contact
Contact getContact(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_CONTACTS, new String[] { KEY_ID,
KEY_TASK, KEY_DATETIME }, KEY_ID + "=?",
new String[] { String.valueOf(id) }, null, null, null, null);
if (cursor != null)
cursor.moveToFirst();
Contact contact = new Contact(Integer.parseInt(cursor.getString(0)),
cursor.getString(1), cursor.getString(2));
// return contact
return contact;
}
// Getting All Contacts
public List<Contact> getAllContacts() {
try {
List<Contact> contactList = new ArrayList<Contact>();
contactList.clear();
System.out.print("clear array list :");
// Select All Query
String selectQuery = "SELECT * FROM " + TABLE_CONTACTS;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
Contact contact = new Contact();
contact.setID(Integer.parseInt(cursor.getString(0)));
contact.setName(cursor.getString(1));
contact.setPhoneNumber(cursor.getString(2));
// Adding contact to list
contactList.add(contact);
} while (cursor.moveToNext());
}
cursor.close();
// return contact list
return contactList;
} catch (Exception e) {
// TODO: handle exception
Log.e("all_contact", "" + e);
}
List<Contact> contactList = new ArrayList<Contact>();
return contactList;
}
// Updating single contact
public int updateContact(Contact contact) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_TASK, contact.getName());
values.put(KEY_DATETIME, contact.getPhoneNumber());
// updating row
return db.update(TABLE_CONTACTS, values, KEY_ID + " = ?",
new String[] { String.valueOf(contact.getID()) });
}
// Deleting single contact
public void deleteContact(Contact contact) {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_CONTACTS, KEY_ID + " = ?",
new String[] { String.valueOf(contact.getID()) });
db.close();
}
// Getting numbers of contacts Count
public int getContactsCount() {
String countQuery = "SELECT * FROM " + TABLE_CONTACTS;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
cursor.close();
// return count
return cursor.getCount();
}
}
最佳答案
您似乎想从不存在的列中读取数据。列 -1 表示在数据库中找不到指定的列。
在这个级别肯定不是服务的问题,而是数据库配置的问题。
关于android - sqlite 失败无法从警报服务中的游标读取游标窗口的第 0 列 -1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18953113/
我正在尝试使用游标遍历表: DEClARE @ProjectOID as nvarchar (100) DECLARE @TaskOID as nvarchar (100) DECLARE TaskO
使用 JOprionPane 时,光标出现了一些问题。我将光标设置到 pharent 框架,然后使用这个显示一个对话框: Object[] possibilities = {"ham", "spam"
我想将数据从一个表(原始数据,所有列都是 VARCHAR)复制到另一个表(使用相应的列格式进行格式化)。 为了将数据从 rawdata 表复制到 formatted 表中,我使用游标来识别受影响的行。
我先走了 我 100% 属于集合运算阵营。但是当设置逻辑时会发生什么在整个所需的输入域上进行检索会导致如此大的检索,以至于查询显着减慢,变得缓慢,或者基本上需要无限的时间? 在这种情况下,我将使用可能
为什么我不能这样做?我想从 TABLEA 中搜索大于光标值的最接近的值,对两者执行平均函数并将结果放入 test3 中。我收到错误代码 1054 未知列“Xnearest in 'field list
我希望以下存储例程返回一系列行,但它只返回 1: CREATE PROCEDURE example() BEGIN DECLARE current_id INT;
我有一张代表患者体检的表,它有检查 ID 和患者 ID。 我想逐行浏览表格并获取每个患者 ID 并比较其不同的咨询,看看它是否被视为“new_attack”。我正在处理疟疾疾病,我们认为每个在过去 6
如文档所述here ,我需要声明一个在打开时接受参数的游标。 我的查询类似于: DECLARE cur CURSOR (argName character varying) FOR SELECT *
我正在尝试使用 PostgreSQL 学习基本游标。这是我的脚本: DECLARE cur_employees CURSOR FOR SELECT * FROM employee CLOS
*DELIMITER // create procedure test(OUT l_out INT) begin DECLARE done INT DEFAULT FALSE; declare l_s
来自 psycopg2 文档: When a database query is executed, the Psycopg cursor usually fetches all the record
我正在使用 while 循环遍历游标,然后输出数据库中每个点的经度和纬度值。 出于某种原因,它没有返回光标中的最后一组(或第一个取决于我是否使用 Cursor.MoveToLast)经度和纬度值。 这
不知道有没有人试过全新的PHPStorm 4 , 但我遇到了这个新版本的问题,而我以前的主要版本 (PHPStorm 3) 没有。 基本上,当我单击代码 View 空白处的任意位置时,光标会设置在该位
mysql的存储过程、游标 、事务实例详解 下面是自己曾经编写过的mysql数据库存储过程,留作存档,以后用到的时候拿来参考。 其中,涉及到了存储过程、游标(双层循环)、事务。 【说明】:代码
Mysql的存储过程是从版本5才开始支持的,所以目前一般使用的都可以用到存储过程。今天分享下自己对于Mysql存储过程的认识与了解。 一些简单的调用以及语法规则这里就不在赘述,网上有许多例子。这里
我正在使用 SQL Server,我有一个包含 3 列(时间序列)的表 data ,带日期,hour开始,AwardStatus . 大部分奖励状态是随机生成的。有两种选择,授予或未授予。 但是,业务
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
Why am getting duplicate records ? pls correct me.Thanks in Advance. declare clazzes_rec clazzes%r
Why am getting duplicate records ? pls correct me.Thanks in Advance. declare clazzes_rec clazzes%r
我需要在数据表中设置一个非唯一标识符。这在组内是连续的,即。对于每个组,ID 应从 1 开始,并以 1 为增量递增,直到该组的最后一行。 下表对此进行了说明。 “新 ID”是我需要填充的列。 Uniq
我是一名优秀的程序员,十分优秀!