如何在 android 中使用 SQL 脚本?
how to use SQL Script in android?
android studio 中有很多我们不知道或不使用其功能的东西,如何使用此功能? sql 脚本
终于得到答案
该脚本位于 assert 文件夹 -scripts 由 SQL Developer
开发
InputStream is = getResources().getAssets().open("SQLScript.sql");
String sql= convertStreamToString(is);
public static String convertStreamToString(InputStream is)
throws IOException {
Writer writer = new StringWriter();
char[] buffer = new char[2048];
try {
Reader reader = new BufferedReader(new InputStreamReader(is,
"UTF-8"));
int n;
while ((n = reader.read(buffer)) != -1) {
writer.write(buffer, 0, n);
}
} finally {
is.close();
}
String text = writer.toString();
return text;
}
SQLiteDatabase db;
db = openOrCreateDatabase("MyDatabase.db", SQLiteDatabase.CREATE_IF_NECESSARY, null );
db.execSQL(sql);
终于得到答案
该脚本位于 assert 文件夹 -scripts 由 SQL Developer
InputStream is = getResources().getAssets().open("SQLScript.sql");
String sql= convertStreamToString(is);
public static String convertStreamToString(InputStream is)
throws IOException {
Writer writer = new StringWriter();
char[] buffer = new char[2048];
try {
Reader reader = new BufferedReader(new InputStreamReader(is,
"UTF-8"));
int n;
while ((n = reader.read(buffer)) != -1) {
writer.write(buffer, 0, n);
}
} finally {
is.close();
}
String text = writer.toString();
return text;
}
SQLiteDatabase db;
db = openOrCreateDatabase("MyDatabase.db", SQLiteDatabase.CREATE_IF_NECESSARY, null );
db.execSQL(sql);