How to use SQL statements of HTML5 Web Database

Source: Internet
Author: User
Tags how to use sql web database

Comments: This article will introduce in detail how to use SQL statements of HTML5 Web Database. For more information, see // openDatabase to open an existing Database, if it does not exist, a database will be created. The parameters are the database name, version, database description, and data size. var db = window. openDatabase ("mydatabase", "1.0", "My database description", 20000 );

How to Use Database SQL statements

Dbname. transaction (function (tx) {tx.exe cuteSql (SQL );});


The Code is as follows:
<! DOCTYPE html>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> </title>
<Style type = "text/css">

</Style>
</Head>
<Body>
<Div>
</Div>
<Script type = "text/javascript">
// Open an existing database using the openDatabase method. If it does not exist, a database will be created.
Var db = window. openDatabase ("mydatabase", "1.0", "My database description", 20000 );
Var d = new Date ();
// Create a data table
Var SQL = "CREATE TABLE mytable (mytitle TEXT, timestamp REAL )";
Db. transaction (function (tx ){
Tx.exe cuteSql (SQL );
});
// Insert data into the data table
Db. transaction (function (tx ){
Tx.exe cuteSql ("insert into mytable (mytitle, timestamp) values (?, ?) ", [" Guangzhou University huasoft software College 3 ", d. toLocaleString ()], null, null );
});
// Delete a data table
// Db. transaction (function (tx ){
// Tx.exe cuteSql ("drop table mytable ");
//});
Db. transaction (function (tx ){
Tx.exe cuteSql ("SELECT * FROM mytable", [],
Function (tx, result ){
For (var I = 0; I <result. rows. length; I ++ ){
Document. write ('Result. rows. item (I) ['mytitle'] + "" +
Result. rows. item (I) ['timestamp'] +
'</H1> ');
}
},
Function (){
Alert ("error ");
});
});
</Script>
</Body>
</Html>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.