HTML5 Web SQL使用

HTML5提出了Web SQL这个新概念。

(1)打开数据库,若数据库不存在,则默认会创建一个新的数据库。

var db = openDatabase('MyDataBase', '2.0', 'This is my database', 2*1024*1024);

(2)创建表

db.transaction(function(ts){
        ts.executeSql('CREATE TABLE IF NOT EXISTS NOTES(id unique, content)');
});

(3)查询

db.transaction(function(ts){
    ts.executeSql('SELECT * FROM Notes', [], function(ts, result){
        if(result.rows.length == 0)
            alert('Nothing found!');
    }, 
    function(ts, error){
        alert(error);
    });
});

 

posted @ 2013-12-13 10:20  寂寞尘埃  阅读(369)  评论(0)    收藏  举报