html ---- web sql 例子
2015-09-11 07:48
555 查看
<!doctype html> <html> <head> <meta charset="utf-8"> <script> window.onload = function () { var one = document.getElementById('one'); if (window.openDatabase) { var dataBase = openDatabase("student", "1.0", "学生表", 1024*1024, function() { }); dataBase.transaction(function (fx) { //创建一个表 fx.executeSql( "create table if not exists stu (id REAL UNIQUE, name TEXT)", [], function () { //表创建成功 alert("表创建成功"); }, function () { //表创建失败 alert("表创建失败"); } ); //插入数据 fx.executeSql( "insert into stu (id, name) values(?, ?)", [1, "张三"], function () { //表创建成功 alert("数据插入成功"); }, function () { //表创建失败 alert("数据插入失败"); } ); //更新数据 fx.executeSql( "update stu set name = ? where id = ?", ["李四", 1], function () { //表创建成功 alert("数据更新成功"); }, function () { //表创建失败 alert("数据更新失败"); } ); //查询数据 fx.executeSql( "select * from stu", [], function (fx, result) { //表创建成功 // alert(result.rows.length); for(var i = 0; i < result.rows.length; i++) { one.innerHTML = result.rows.item(i)['name']; } alert("数据查询成功"); }, function () { //表创建失败 alert("数据查询失败"); } ); //删除数据 fx.executeSql( "delete from stu where id=?", [1], function (fx, result) { //表创建成功 one.innerHTML = ""; }, function () { //表创建失败 alert("删除失败"); } ); //删除表 fx.executeSql( "drop table stu", [], function (fx, result) { //表创建成功 alert("表删除成功"); }, function () { //表创建失败 alert("表删除失败"); } ); }) } } </script> </head> <body> <p id="one">测试</p> </body> </html>
相关文章推荐
- 给各位聚聚和大大介绍一个开源项目 Expression2Sql
- 11g之前 修改主机名后如何启动使用ASM存储的数据库
- java中mongodb的查询及排序
- MySQL for mac如何调出命令行客户端MySQL Command Line Client
- 数据库原理之求关系的闭包
- mysql 查询某一主键在那些表中中被设置为外键了
- MYSQL创建一个function用来计算经纬度距离
- MySQL TEXT类型
- 自己在安装MYSQL常见问题
- Redis官网——如何利用Redis做服务器集群的分布式锁
- 关于mysql的字段长度含义问题。
- redis的主从配置问题
- MYSQL-InnoDB事务隔离级别
- ORACLE BETWEEN AND查询时间段
- mysql order by多字段排序
- MYSQL创建一个function用来计算经纬度距离
- 数据库分页以及目录遍历
- java中memcached基本使用方法
- MYSQL支持的数据类型——字符串类型
- 4.windows环境下如何安装memcached教程(转载+自己整理)