我的数据库文件在哪里创建

时间:2012-11-14 19:38:56

标签: android sqlite ormlite

这是我的文件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卡中的路径吗?

2 个答案:

答案 0 :(得分:3)

它将存储在

/data/data/[package name]/databases

但除非您的手机是root用户,否则无法使用文件浏览器或adb shell浏览到它

答案 1 :(得分:0)

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

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