I created DBHelper.java class in my android project. In my OnCreate() method I create tables to my database, but I also want to insert rows to these tables. So I made file - script.sql, that contains my insert queries. Everything would work fine, but I cannot solve one problem - context.
This is my code I put in DBHelper class:
private void executeScript()
{
InputStream inputStream = this.getResources().openRawResource(R.raw.script); // I get error here.
byte[] buffer = new byte[7844];
String queries = "";
try {
inputStream.read(buffer);
queries = new String(buffer,"UTF-8");
} catch (Exception e) {
Log.e("Error", e.toString());
}
for (String query : queries.split(";")) {
Log.e("Query", query);
}
}
I get error in line : this.getResources()... I know that I can't use this, but what can I do instead? I know this code just displays logs, but I'll add execSQL later.