加入收藏 | 设为首页 | 会员中心 | 我要投稿 西安站长网 (https://www.029zz.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 建站 > 正文

数据库版本如何单独升级,并且将原有数据迁移过去

发布时间:2019-07-19 04:15:14 所属栏目:建站 来源:Android架构师
导读:副标题#e# 在我们开发的应用中,一般都会涉及到数据库,使用数据的时候会涉及到数据库的升级、数据的迁移、增加行的字段等。比如,用户定制数据的保存,文件的端点续传信息的保存等都会涉及到数据库。 我们应用第一个版本是V1.0,在迭代版本V1.1 时,我们在

导入已有数据库

  1. /** 
  2.  * Created by Owen Chan 
  3.  * On 2017-09-26. 
  4.  */ 
  5. public class DbManager { 
  6.  public static final String PACKAGE_NAME = "com.example.sql"; 
  7.  public static final String DB_NAME = "table.db"; 
  8.  public static final String DB_PATH = "/data/data/" + PACKAGE_NAME; 
  9.  private Context mContext; 
  10.  public DbManager(Context mContext) { 
  11.  this.mContext = mContext; 
  12.  } 
  13.  public SQLiteDatabase openDataBase() { 
  14.  return SQLiteDatabase.openOrCreateDatabase(DB_PATH + "/" + DB_NAME, null); 
  15.  } 
  16.  public void importDB() { 
  17.  File file = new File(DB_PATH + "/" + DB_NAME); 
  18.  if (!file.exists()) { 
  19.  try { 
  20.  FileOutputStream out = new FileOutputStream(file); 
  21.  int buffer = 1024; 
  22.  InputStream in = mContext.getResources().openRawResource(R.raw.xxxx); 
  23.  byte[] bts = new byte[buffer]; 
  24.  int lenght; 
  25.  while ((lenght = in.read(bts)) > 0) { 
  26.  out.write(bts, 0, bts.length); 
  27.  } 
  28.  out.close(); 
  29.  in.close(); 
  30.  } catch (Exception e) { 
  31.  e.printStackTrace(); 
  32.  } 
  33.  } 
  34.  } 

(编辑:西安站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读