我看到我可以使用shell命令执行.sql文件...
Process process = Runtime.getRuntime().exec(commandLine);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
“commandLine”属性必须是这样的?
commandLine = "sqlite> .read database.sql";
另一个疑问......我应该在哪里保存我的“database.sql”文件?进入资产?我试过这样做但没有奏效...... 有人知道怎么做吗?
答案 0 :(得分:2)
我看到我可以使用shell命令执行.sql文件
这将是一个非常糟糕的主意。没有shell命令是Android SDK的一部分,因此保证在所有设备上。
读入SQL脚本并通过execSQL()
和SQLiteDatabase
上的亲属执行其声明,也许使用beginTransaction()
和亲属将它们包装在您自己的交易中。