var con; var Class = { create: function() { return function() { this.initialize.apply(this, arguments); } } } var DataBase = new Class.create(); DataBase.prototype = { initialize: function(filename,datafile) { var filePath = location.href.substring(0, location.href.indexOf(filename)); filePath=decodeURI(filePath); var path = filePath + datafile; //去掉字符串中最前面的"files://"这8个字符。 path = path.substring(8); //建立连接,并生成相关字符串 www.knowsky.com。 con = new ActiveXObject("ADODB.Connection"); con.Provider = "Microsoft.Jet.OLEDB.4.0"; con.ConnectionString = "Data Source=" + path; con.open(); }, close:function(){//关闭 con.close(); con = null; }, execute:function(sql){//执行sql不返回 con.execute(sql); }, openRs:function(sql){//执行sql返回rs var rs = new ActiveXObject("ADODB.Recordset"); rs.open(sql, con); return rs; } }
使用方法:
如在test.html文件中使用
本文介绍了一种使用JavaScript操作本地数据库的方法,包括打开数据库连接、执行SQL查询并获取结果等过程。通过示例展示了如何读取特定字段的数据并进行简单处理。

被折叠的 条评论
为什么被折叠?



