android sqlite 列名,Android SQLite求帮助 。cursor.getCount()返回0,但列名能查出来。烦死了小弟我都,求大神指点。...

Android SQLite求帮助 。。cursor.getCount()返回0,但列名能查出来。。烦死了我都,求大神指点。。

本帖最后由 zdxxinlang 于 2014-04-25 18:20:44 编辑

Android 求大神救命吖!!我读取一个RAW下的数据库,cursor可以查出列名,但是查不出来行里的数据,

cursor.getCount()返回0,但是cursor.getColumnCount()能返回正常的5.ps:用的SQL语句是select * 吖,既然能查出来

列数和列名就表示应该连上了啊,但为什么就是查不出来,都快疯了!!

Android 求大神救命吖!!我读取一个RAW下的数据库,cursor可以查出列名,但是查不出来行里的数据,

cursor.getCount()返回0,但是cursor.getColumnCount()能返回正常的5.ps:用的SQL语句是select * 吖,既然能查出来

列数和列名就表示应该连上了啊,但为什么就是查不出来,都快疯了!!

这是DataBaseHelper类

package com.xxjz.dbServer;

import android.content.Context;

import android.database.sqlite.SQLiteDatabase;

import android.database.sqlite.SQLiteOpenHelper;

public class DataBaseHelper extends SQLiteOpenHelper {

private static final String NAME="thepaper.db";

private static final int version=1;

public DataBaseHelper(Context context){

super(context, NAME, null, version);

}

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

//db.execSQL("create table Qindex (type char,year char,month char,roll char,qIndex char)");

// db.execSQL("create table Qquestions (isImport int,isWrong int,xmlFileName string,isCollection int,id int , kind string, answer string, analysis string)");

}

@Override

public void onCreate(SQLiteDatabase db) {

db.execSQL("create table Qindex (type char,year char,month char,roll char,qIndex char)");

db.execSQL("create table Qquestions (isImport int,isWrong int,xmlFileName string,isCollection int,id int , kind string, answer string, analysis string)");

}

}

这是获取SQLiteDatabase对象的类,数据库文件放在res\raw下。

package com.xxjz.dbServer;

import java.io.File;

import java.io.IOException;

import android.content.Context;

import android.content.ContextWrapper;

import android.database.DatabaseErrorHandler;

import android.database.sqlite.SQLiteDatabase;

import android.database.sqlite.SQLiteDatabase.CursorFactory;

import android.util.Log;

public class DatabaseContext extends ContextWrapper {

public DatabaseContext(Context base) {

super(base);

// TODO Auto-generated constructor stub

}

public File getDatabasePath(String name) {

//判断是否存在sd卡

boolean sdExist = android.os.Environment.MEDIA_MOUNTED.equals(android.os.Environment.getExternalStorageState());

if(!sdExist){//如果不存在,

Log.e("SD卡管理:", "SD卡不存在,请加载SD卡");

return null;

}

else{//如果存在

//获取sd卡路径

String dbDir=android.os.Environment.getExternalStorageDirectory().getAbsolutePath();

dbDir += "/res/raw";//数据库所在目录

String dbPath = dbDir+"/"+name;//数据库路径

//判断目录是否存在,不存在则创建该目录

System.out.println(">>>>>>>>>>>>>"+dbPath);

File dirFile = new File(dbDir);

if(!dirFile.exists())

dirFile.mkdirs();

//数据库文件是否创建成功

boolean isFileCreateSuccess = false;

//判断文件是否存在,不存在则创建该文件

File dbFile = new File(dbPath);

if(!dbFile.exists()){

try {

isFileCreateSuccess = dbFile.createNewFile();//创建文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值