Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try this Hope this help you</p> <pre><code>import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.BufferedInputStream; import java.io.IOException; public class SmartOpenHelper extends SQLiteOpenHelper { private Context context; private String DB_SQL; SmartOpenHelper(Context context, String dbname, int dbversion, String dbSqlName) throws IOException { super(context, dbname, null, dbversion); this.context = context; this.DB_SQL = dbSqlName; } @Override public void onCreate(SQLiteDatabase db) { try { BufferedInputStream inStream = new BufferedInputStream(context.getAssets().open(DB_SQL)); String sql = ""; int character = -2; do { character = inStream.read(); if ((character != -1) &amp;&amp; (character != -2)) sql += (char) character; else break; } while (true); System.out.println("onCreate DB SQL = " + sql.split("\n")); String[] arrSQL = sql.split("\n"); for (int i = 0; i &lt; arrSQL.length; i++) { db.execSQL(arrSQL[i]); } } catch (IOException e) { e.printStackTrace(); } } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { try { BufferedInputStream inStream = new BufferedInputStream(context.getAssets().open(DB_SQL)); String sql = ""; int character = -2; do { character = inStream.read(); if ((character != -1) &amp;&amp; (character != -2)) sql += (char) character; else break; } while (true); System.out.println("onUpgrade DB SQL = " + sql.split("\n")); String[] arrSQL = sql.split("\n"); for (int i = 0; i &lt; arrSQL.length; i++) { db.execSQL(arrSQL[i]); } } catch (IOException e) { e.printStackTrace(); } } public synchronized void close() { super.close(); } } </code></pre> <p><strong>How to use</strong></p> <pre><code>SmartOpenHelper openHelper = new SmartOpenHelper(this.context, DATABASE_NAME, DATABASE_VERSION, DATABASE_SQL); SQLiteDatabase db = openHelper.getWritableDatabase(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload