我正在为android开发一个电话间隙应用程序,在资源文件夹中使用.db扩展名保存数据库,在应用程序的java文件上我将数据库复制到我的应用程序数据库(代码如下),现在假设我有两个按钮(一个用于打开外部链接,另一个用于打开数据库并从db获取数据。启动应用程序时,我点击从数据库按钮获取数据,其成功完整并执行查询,现在当我点击按钮打开我的应用程序的浏览器链接时,它打开inappbrowser中的链接,现在我点击后退按钮,我们现在是我们的应用程序页面如果我点击按钮从数据库中获取数据它的发送错误“SqliteDatabaseCpp(28065):sqlite返回:错误代码= 1,msg =没有这样的表:tblProduct “
所以任何人都可以建议我在哪里错了,我的复制数据库代码和执行查询如下:
将数据复制到数据库的Java代码:
public void onCreate(Bundle savedInstanceState) {
try {
this.copy("Databases.db", "/data/data/" + pName + "/app_database/");
this.copy("0000000000000001.db", "/data/data/" + pName
+ "/app_database/file__0/");
super.onCreate(savedInstanceState);
super.loadUrl(
"file:///android_asset/www/index.html",
2000);
super.appView.setVerticalScrollBarEnabled(true);
super.appView.setHorizontalScrollBarEnabled(false);
super.appView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
} catch (IOException e) {
e.printStackTrace();
}
}
// Copy Paste this function in the class where you used above part
void copy(String file, String folder) throws IOException {
Log.d("GRT", "We are in the copy of db");
File CheckDirectory;
CheckDirectory = new File(folder);
if (!CheckDirectory.exists()) {
Log.d("GRT", "Creating copy of db db");
CheckDirectory.mkdir();
} else {
Log.d("GRT", "Databse already exists");
}
InputStream in = getApplicationContext().getAssets().open(file);
OutputStream out = new FileOutputStream(folder + file);
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0)
out.write(buf, 0, len);
in.close();
out.close();
}
HTML按钮(一个用于打开inappbrowser,另一个用于查询数据库):
<a data-role="button" onclick="openInapp()">open inapp browser</a>
<a data-role="button" onclick="queryRecommded()">View Recommended Product</a>
相应的.js文件代码为:
function onDeviceReady()
{
var db = window.openDatabase("Database", "1.0", "GRTDB", 3000000);
db.transaction(queryRecommondedProduct, errorCB2, successCB);
}
function queryRecommondedProduct(tx){
console.log("tx"+tx)
try{
//alert("SQL gonna run now");
var progressHud =window.plugins.waitingDialog;
progressHud.show("Loading...Please wait");
tx.executeSql("Select aa.ProductID,aa.ProductName,aa.Price,aa.Description,aa.Specification,aa.VideoLink,ab.GalleryID,ab.Location,ab.ImageName,ab.LocalFolder,aa.Buy_Now from tblProduct aa inner join tblGallery ab on aa.ProductId=ab.ProductId where aa.ProductId=(select RecomProdId from tblQuery where AnswerQ1='"+"townhouse"+"' AND AnswerQ2='"+"small"+"' AND AnswerQ3='"+"several"+"' AND AnswerQ4='"+"medium duty"+"' AND AnswerQ5='"+"monthly"+"' AND IsDeleted='0' ORDER BY ProductAnswerId ASC LIMIT 1 ) and aa.IsDeleted ='0' and ab.IsDeleted ='0' and ab.IsDownLoad ='1'", [],function(tx,result){queryRecommdedSuccess(tx,result,"isReccom")}, errorCB4);
}
catch(e){alert("test"+e);}
}
function queryRecommdedSuccess(tx,result,rflag){
console.log("Step2"+result.rows.length)
// alert("Step2 - "+result.rows.length);
if(result.rows.length>0){
}
}
function errorCB2(err){
alert("Error2 is::--- "+err.code);
}
function successCB(){
}
function **queryRecommded**()
{
document.addEventListener("deviceready", onDeviceReady, false);
}
function openInapp(){
iabRef = window.open('http://apache.org', '_blank', 'location=yes');
iabRef.addEventListener('loadstart', iabLoadStart);
iabRef.addEventListener('loadstop', iabLoadStop);
iabRef.removeEventListener('loaderror', iabLoadError);
iabRef.addEventListener('exit', iabClose);
}
答案 0 :(得分:2)
我的问题在_system
值处使用target
解决了。
window.open(网址,目标,选项);
target
值:
_self - opens in the Cordova WebView if url is in the white-list, else it opens in the InAppBrowser
_blank - always open in the InAppBrowser
_system - always open in the system web browser
答案 1 :(得分:2)
由于我需要使用inAppBrowser
创建target= "_blank"
并使用数据库连接返回,我决定深入调查并找到适用于我的“修复”。
在源文件中(在我的例子中是Android(InAppBrowser.java))我只是评论那些行是这样的结果:
if (enableDatabase) {
//String databasePath = cordova.getActivity().getApplicationContext().getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath();
//settings.setDatabasePath(databasePath);
settings.setDatabaseEnabled(true);
}