Android的失败,我的设备上创建一个SQL数据库 [英] Android fails to create a SQL database on my device

查看:192
本文介绍了Android的失败,我的设备上创建一个SQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些简单的code应该创建一个数据库。

I have some simple code which should create a database.

package com.webfoo.android.databaseExample;

import android.app.Activity;
import android.os.Bundle;

public class DatabaseExampleActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        jokesHelper db = new jokesHelper(getBaseContext());
    }
}


package com.webfoo.android.databaseExample;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class jokesHelper extends SQLiteOpenHelper {

    private static final String DATABASE_NAME = "test.db";
    private static final int DB_VERSION = 1;

    public jokesHelper(Context context) {
        super(context, DATABASE_NAME, null, DB_VERSION);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL("create table todo (_id integer primary key autoincrement, "
                 + "joke text not null, punch text not null);");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub

    }

}

没有任何有任何想法,为什么这不能创建数据库?我的手机连接到我的机器和SD没有安装,但它是在调试模式(我可以看到我的外接正在跑了我的手机上)。

does any have any idea why this fails to create a database? My phone is connected to my machine and the SD isn't mounted, but it's on debug mode (i can see my add being ran on my phone).

我没有修改清单要么,所以这可能会造成的任何问题?

I haven't modified the manifest either, so could that be causing any issues?

感谢

推荐答案

您还没有叫 getWritableDatabase() getReadableDatabase()呢。

例如

jokesHelper dbHelper = new jokesHelper(getBaseContext());
SQLiteDatabase db = dbHelper.getWritableDatabase();

数据库未存储在SD卡或USB挂载存储(至少不是默认情况下)上。它们在内部存储器。上面您的评论的路径是差不多吧,但我不知道什么是DATA的意思。路径是: /数据/数据​​/<包名称> /数据库。您可以检查通过使用亚行外壳LS /数据/数据​​/<包名称> /数据库

The databases are not stored on the SD card or otherwise USB-mountable storage (at least not by default). They are in "internal" storage. The path in your comment above is almost right, but I'm not sure what "DATA" means. The path is: /data/data/<package name>/databases. You can check that by using adb shell ls /data/data/<package name>/databases.

这篇关于Android的失败,我的设备上创建一个SQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆