【发布时间】:2016-07-22 07:12:48
【问题描述】:
我想预先填充我的数据库。所以我从浏览器生成 SQL 查询并编写代码将它们插入到数据库中。它适用于单行查询,但大多数插入查询都有多行,例如 `
INSERT INTO `poem` VALUES (780,'سلام القلب واشواقه
من قلب يحب مجنونه
ياليت هالقلب يحن
ويقول هالدنيا
ماتسوى دون *_*','0',NULL);`
我的要求是按原样插入它们。这就是我为多行编写的方法(非常适合单行查询)
public static int countLines(InputStream is) throws IOException {
try {
byte[] c = new byte[1024];
int count = 0;
int readChars = 0;
boolean empty = true;
int index = 0;
while ((readChars = is.read(c)) != -1) {
empty = false;
String temp = new String(c);
for (int i = 0; i < readChars; i++) {
if (c[i] == ';' && index == 0) {
index++;
} else if (c[i] == '\n' && index == 1) {
index++;
} else if (c[i] == '\t' && index == 2) {
index++;
} else if (c[i] == 'I' && index == 3) {
count++;
index = 0;
} else {
i -= index;
index = 0;
}
}
}
return (count == 0 && !empty) ? 1 : count + 1;
} finally {
is.close();
}
}
任何人都知道如何将此类查询从文件插入到数据库中。? 任何帮助都会很棒。谢谢
【问题讨论】:
-
你为什么不直接ship the DB with the app?
标签: java android sqlite android-assets