我有要使用JavaScript访问的SQLite DB文件。它有1个称为users
的表,并且其中有1条记录。下面是SQLite DB浏览器的屏幕截图:
下面是我的 index.html 代码:
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
var db = openDatabase('electron.db', '1.0', 'Test DB', 2 * 1024 * 1024);
var msg;
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM users', [], function (tx, results) {
var len = results.rows.length, i;
msg = "<p>Found rows: " + len + "</p>";
document.querySelector('#status').innerHTML += msg;
for (i = 0; i < len; i++){
msg = "<p><b>" + results.rows.item(i).word + "</b></p>";
document.querySelector('#status').innerHTML += msg;
}
}, null);
});
</script>
</head>
<body>
<div id="status" name="status">Status Message</div>
</body>
</html>
如果需要,我的SQLite数据库链接-https://filebin.net/qb6h4tafcyagc2pg