Where is my database file created

╄→гoц情女王★ 提交于 2019-12-11 23:25:28

问题


This is my file dataSqliteHelper and when I run the first time, the data file is created but I don't know where is it to get it and open it with a tool and view the file.

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();

}

   }

with this line I know that I give the file name

super(context, DATABASE_NAME, null, DATABASE_VERSION);

but where is it in the storage of the device?

By the way , can I change the path to store the file in the sd card ?


回答1:


it will be stored at

/data/data/[package name]/databases

But unless your phone is rooted you cannot browse to it using file explorer or adb shell




回答2:


It is saved here (as nandeesh says) /data/data/[package name]/databases

You can only access it on a phone if it is rooted. Or you can install the app on an emulator, start up the DDMS tool and view the database file there.



来源:https://stackoverflow.com/questions/13386066/where-is-my-database-file-created

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!