Note that there are some explanatory texts on larger screens.

plurals
  1. POshare database with native android and html5 (sqlite error no such table)
    text
    copied!<p>I'm trying to create an application that share database with native android and html. I initialize the below code and enable database for my webview page. But at the webview page, I get no such table (hybrid_user) when I update the database. I'm not sure what I missed here. </p> <p><strong>Database</strong></p> <pre><code>public class DBHelper extends SQLiteOpenHelper{ private SQLiteDatabase helper; private static final String DATABASE_NAME="hybrid_db"; private static final int SCHEMA_VERSION=1; private static final String TAG = "DBHelper"; public DBHelper(Context context){ super(context, DATABASE_NAME, null, SCHEMA_VERSION); } @Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub Log.i(TAG, "DBHelper"); db.execSQL("CREATE TABLE hybrid_user (" + "tableid INTEGER PRIMARY KEY AUTOINCREMENT, " + "userid TEXT," + "password TEXT," + "mobile TEXT," + "createdate TIMESTAMP default current_timestamp);"); } </code></pre> <p><strong>Activity</strong></p> <pre><code> webView = (WebView)findViewById(R.id.webView); webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl("file:///android_asset/www/index.html"); webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); webView.getSettings().setDatabaseEnabled(true); webView.getSettings().setDatabasePath("/data/data/com.example.hybrid/hybrid_db"); webView.getSettings().setDomStorageEnabled(true); webView.setWebViewClient(new WebViewClient(){ @Override public void onPageFinished(WebView view, String url){ webView.loadUrl("javascript:callFromActivity(\""+userid+"\")"); } }); webView.setWebChromeClient(new WebChromeClient(){ public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize, long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater){ quotaUpdater.updateQuota(204801); } }); </code></pre> <p><strong>index.html</strong></p> <pre><code>&lt;script&gt; var hybrid_user = null; function errorHandler(transaction, error){ alert('Error:'+error.message+' (Code '+error.code+')'); return true; } window.onerror = errorHandler; try{ if(window.openDatabase){ var shortName = 'hybrid_db'; var version = '1.0'; var displayName = 'Hybrid Database'; var maxSize = 204801; hybrid_user = openDatabase(shortName, version, displayName, maxSize); alert("alert: "+hybrid_user); } else{ alert("Database is not supported"); } } catch(e){ if(e == 2){ alert("Invalid database version."); } else{ alert("Unknown error "+e+"."); } return; } function updateRecord(){ hybrid_user.transaction( function(transaction){ transaction.executeSql("UPDATE hybrid_user SET mobile=? WHERE userid ='"+document.getElementById("userid")+"'", [mobileNum]); alert("mobileNum:" +mobileNum); alert("userid:" +document.getElementById("userid")); }); } &lt;/script&gt; &lt;body&gt; &lt;form&gt; &lt;fieldset&gt; &lt;legend&gt;Hybrid Application&lt;/legend&gt; &lt;p&gt; &lt;label&gt;UserName: &lt;/label&gt; &lt;p id="userid"&gt;&lt;/p&gt; &lt;p&gt; &lt;label&gt;Mobile Number :&lt;/label&gt; &lt;input type = "text" id = "mobileNum" /&gt; &lt;/p&gt; &lt;button type="button" onclick="updateRecord()"&gt;Submit&lt;/button&gt; &lt;div id="output"&gt;&lt;/div&gt; &lt;/fieldset&gt; &lt;/form&gt; &lt;/body&gt; </code></pre> <p>I get <code>alert:[object Database]</code> from the <code>alert("alert:" +hybrid_user);</code>. But still I get sqlite error no such table. <code>sqlite returned: error code = 1, msg = no such table:hybrid_user</code></p>
 

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