0
A
回答
2
下面是一個簡單的步行通過
//variables
var db;
var shortName = 'MyDB';
var version = '1.0';
var displayName = 'MyDB';
var maxSize = 200000;
// this is called when an error happens in a transaction
function errorHandler(transaction, error) {
alert('Error: ' + error.message + ' code: ' + error.code);
}
// this is called when a successful transaction happens
function successCallBack() {
alert("DEBUGGING: success");
}
function nullHandler(){}
// called when the application loads
function onBodyLoad(){
// This alert is used to make sure the application is loaded correctly
// you can comment this out once you have the application working
alert("DEBUGGING: we are in the onBodyLoad() function");
if (!window.openDatabase) {
// not all mobile devices support databases if it does not, the following alert will display
// indicating the device will not be albe to run this application
alert('Databases are not supported in this browser.');
return;
}
// this line tries to open the database base locally on the device
// if it does not exist, it will create it and return a database object stored in variable db
db = openDatabase(shortName, version, displayName,maxSize);
// this line will try to create the table User in the database just created/openned
db.transaction(function(tx){
// you can uncomment this next line if you want the User table to be empty each time the application runs
//tx.executeSql('DROP TABLE user',nullHandler,nullHandler);
// this line actually creates the table User if it does not exist and sets up the three columns and their types
// note the UserId column is an auto incrementing column which is useful if you want to pull back distinct rows
// easily from the table.
tx.executeSql('CREATE TABLE IF NOT EXISTS user(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, username TEXT NOT NULL, password TEXT NOT NULL)',[],nullHandler,errorHandler); },errorHandler,successCallBack);
}
-1
首先擊中谷歌create database websql
:
如果嘗試打開一個不存在的數據庫時,API將動態創建 它爲你。您也不必擔心關閉數據庫 。
var db = openDatabase(dbName, '1.0', dbDescription, dbSize);
/**
Params:
Database name
Version number
Text description
Estimated size of database
相關問題
- 1. 在WebSQL中創建數據庫
- 2. 如何在Tryton創建新數據庫
- 3. 如何在不使用WebSQL API的情況下創建sqlite數據庫?
- 4. 如何從JavaScript壓縮WebSQL數據庫
- 5. 如何使用WebSQL訪問數據庫?
- 6. 如何在hqsl數據庫管理器中創建新的數據庫?
- 7. 在數據庫sqlite中創建新表
- 8. 如何在SQL Server中創建數據庫的數據庫圖
- 9. 如何在LMDB中創建數據庫?
- 10. 如何在Sqlite中創建數據庫?
- 11. 如何在Hbase中創建數據庫?
- 12. 如何在C++中創建數據庫
- 13. 如何在Azure中創建數據庫?
- 14. 如何在android中創建數據庫?
- 15. 我如何在sql腳本上創建新的數據庫庫
- 16. WebSQL數據庫創建,然後刪除自己
- 17. 如何在貓鼬中創建一個新的數據庫?
- 18. phpBB,如何在舊數據庫中創建新的安裝點?
- 19. 如何在redhat linux中創建新的數據庫實例
- 20. 如何在MySQL Workbench 6.0中創建一個新的數據庫?
- 21. 如何使用PyMongo在MongoDB中創建新的數據庫?
- 22. 如何在流星中創建一個新的數據庫?
- 23. SQL何時創建新的數據庫?
- 24. 如何在SQL Server中從現有數據庫創建新數據庫
- 25. 如何在websql中爲數據庫提供安全
- 26. 如何在html5 websql數據庫中保存並獲取圖片?
- 27. 如何在數據庫中創建數據庫(postgres)?
- 28. 如何創建數據庫
- 29. Websql不創建表
- 30. 如何在Android中刪除並重新創建數據庫?
Downvote?!做什麼的? – DanFromGermany