2012-11-14 67 views
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卡中的文件?

回答

3

它會被存儲在

/data/data/[package name]/databases 

但是,除非你的手機紮根,你可以使用

+2

另外 - 你應該沒有問題在你的虛擬設備上訪問它。 – dispake

+0

謝謝我會試試 – exequielc

+0

@exequielc您可以打開應用程序的調試模式,將它安裝到您的真實設備上,然後使用它將該文件複製到SD卡:'adb shell run-as yourpackage cat/data/data/[yourpackage]/databases/[your-db-name]>/mnt/sdcard/[your-db-name]'。稍後,您可以將它拉到您的機器上:'adb pull/mnt/sdcard/[your-db-name]/path-to-dir-on-machine-'。 – 2012-11-14 19:52:53

0

在此保存(如nandeesh說),文件瀏覽器或亞行外殼 /data/data/[package name]/databases

無法瀏覽到它

您只能在電話上訪問它,如果它是根源的。或者你可以在模擬器上安裝應用程序,啓動DDMS工具並在那裏查看數據庫文件。

+0

它可能改變路徑存儲此文件到SD卡? – exequielc

相關問題