0

这是我的文件dataSqliteHelper,当我第一次运行时,会创建数据文件,但我不知道在哪里获取它并使用工具打开它并查看文件。

public class DataSQLiteHelper extends OrmLiteSqliteOpenHelper {
public static final String DATABASE_NAME = "ventasdb.db";

private static final int DATABASE_VERSION = 1;
private Context mContext;


private Dao<Customer, Integer> customerDao;


public DataSQLiteHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db, ConnectionSource conections) {
    try {

        TableUtils.createTable(connectionSource, Customer.class);


    } catch (Exception e) {
        Log.e(DataSQLiteHelper.class.getName(), "Can't create database", e);
        throw new RuntimeException(e);
    }

}

@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource,
        int oldVersion, int newVersion) {
    try {
        TableUtils.dropTable(connectionSource, Customer.class, true);

    } catch (SQLException e) {
        throw new RuntimeException(e);
    } catch (java.sql.SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

/**
 * Returns the Database Access Object (DAO) for our UserData class. It will
 * create it or just give the cached value.
 */
public Dao<Customer, Integer> getCustomerDao() {
    if (customerDao == null) {
        try {
            customerDao = getDao(Customer.class);
        } catch (java.sql.SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return customerDao;
}



public boolean updateCustomer(Customer p) {
    boolean ret = false;
    if (customerDao != null) {
        try {

            customerDao = getDao(Customer.class);

            UpdateBuilder<Customer, Integer> updateBuilder = customerDao
                    .updateBuilder();
            updateBuilder.updateColumnValue("name", "PIRIPIPI"); // p.getName());
            updateBuilder.updateColumnValue("cel", p.getCel());
            updateBuilder.updateColumnValue("email", p.getEmail());
            updateBuilder.updateColumnValue("address", p.getAddress());
            updateBuilder.updateColumnValue("City", p.getCity());

            // but only update the rows where the description is some value
            updateBuilder.where().eq("customerID", 0);
            // actually perform the update

            customerDao.update(p);
            customerDao.refresh(p);

        } catch (Exception e) {
            ret = false;
            e.printStackTrace();
        }
    }
    return ret;
}

/**
 * Close the database connections and clear any cached DAOs.
 */
@Override
public void close() {
    super.close();

}

   }

通过这一行,我知道我给出了文件名

super(context, DATABASE_NAME, null, DATABASE_VERSION);

但它在设备的存储中在哪里?

顺便问一下,我可以更改将文件存储在 sd 卡中的路径吗?

4

2 回答 2

3

它将存储在

/data/data/[package name]/databases

但除非您的手机已植根,否则您无法使用文件资源管理器或 adb shell 浏览它

于 2012-11-14T19:41:01.417 回答
0

它保存在这里(如nandeesh所说) /data/data/[package name]/databases

如果它是根,您只能在手机上访问它。或者您可以在模拟器上安装应用程序,启动 DDMS 工具并在那里查看数据库文件。

于 2012-11-14T20:22:50.237 回答