我有兩個數據庫,一個數據庫是主要的。這個主數據庫負責保存最新的當前數據,並且通過cron作業填充我的輔助數據庫,一旦主數據庫過時,我想用輔助數據庫替換它,只需通過寫一個文件操作現有的數據庫和刷新我的看法。有沒有可能做到這一點,有沒有更好的辦法?在運行時用另一個數據庫替換數據庫。
到目前爲止,我所做的是:
public void writeToSD() throws IOException {
File f=new File("/mnt/sdcard/dump.db");
FileInputStream fis=null;
FileOutputStream fos=null;
try{
fis=new FileInputStream(f);
fos=new FileOutputStream("/data/data/com.one.two/databases/Bdr");
while(true){
int i=fis.read();
if(i!=-1){
fos.write(i);
}
else{
break;
}
}
fos.flush();
}
catch(Exception e){
e.printStackTrace();
}
finally{
try{
fos.close();
fis.close();
}
catch(IOException ioe){
System.out.println(ioe);
}
}
爲什麼主數據庫獲取過時如果它是最新的?什麼是更改爲第二個數據庫的原因? – sqlab
主數據庫每五分鐘過時一次。數據值改變! – User3
爲什麼你不更新主數據庫? – sqlab