0

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 ?

exequielc
  • 681
  • 1
  • 11
  • 32

2 Answers2

3

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

nandeesh
  • 24,740
  • 6
  • 69
  • 79
  • 2
    additionally - you should have no problem access it on your virtual device. – dispake Nov 14 '12 at 19:43
  • @exequielc You can turn on debug mode of your app, install it on your real device, and use this to copy the file to SD card: `adb shell run-as yourpackage cat /data/data/[yourpackage]/databases/[your-db-name] > /mnt/sdcard/[your-db-name]`. Later you can pull it to your machine: `adb pull /mnt/sdcard/[your-db-name] /path-to-dir-on-your-machine`. –  Nov 14 '12 at 19:52
  • how to I have to do to change the path to store the file in sd card? – exequielc Nov 15 '12 at 13:31
  • check this http://stackoverflow.com/questions/7229450/sqliteopenhelper-creating-database-on-sd-card?lq=1 – nandeesh Nov 15 '12 at 13:34
0

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.

Sababado
  • 2,524
  • 5
  • 33
  • 51