Javascript连接Access数据库完整实例_javascript技巧
程序员文章站
2022-04-08 14:32:45
...
本文实例讲述了Javascript连接Access数据库的方法。分享给大家供大家参考。具体实现方法如下:
var roc = roc || {}; roc.db = roc.db ||{}; //创建一个连接 roc.db.createDb = function(){ var conn = new ActiveXObject("ADODB.Connection"), fso = new ActiveXObject("Scripting.FileSystemObject"), connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fso.GetFile("./db/Sigma.mdb"); conn.Open(connstr);//打开数据库 roc.db.conn = conn; return roc.db.conn; }; //获取连接 roc.db.getDb = function(){ if( roc.db.conn ){ return roc.db.conn; }else{ return roc.db.createDb(); } }; //关闭连接 roc.db.closeConn = function(){ if( roc.db.conn ){ roc.db.conn.close(); roc.db.conn = null; } }; //获取结果集 roc.db.getRs = function( sqlStr ){ var mysql = roc.dom.trim( sqlStr ); if(mysql == ''){return;} var rs = new ActiveXObject("ADODB.Recordset"), myConn = roc.db.getDb(); rs.open( sqlStr , myConn ); return rs; }; //关闭结果集 roc.db.closeRs = function( rs ){ rs.close(); rs =null; }; //更新、插入 roc.db.execute = function( sqlStr ){ var myConn = roc.db.getDb(); myConn.execute( sqlStr ); roc.db.closeConn(); }; /*---------Sigma:“我任你践踏我的尊严而毫不生气,是因为我爱你。”---------*/ roc.dom = roc.dom ||{}; roc.dom.id = function( id ){ if(typeof id == 'string' || id instanceof String) { return document.getElementById(id); } else if(id && id.nodeName && (id.nodeType == 1 || id.nodeType == 9)) { return id; } return null; }; /** * @method tagName 根据标签获取指定dom元素 * @param {String} tagName 元素标签名称 * @param {HTMLElement} el 元素所属的文档对象 默认为当前文档 * @return {HTMLElement} 返回HTMLElement元素 */ roc.dom.tagName = function(tagName, el) { var el = el || document; return el.getElementsByTagName(tagName); }; //删除左右两端的空格 roc.dom.trim = function (str) { return (str+'').replace(/(^\s*)|(\s*$)/g, ""); } /** * @method show 显示目标元素 * @param {Element} element 目标元素或目标元素的id * @param {String} element 目标元素 */ roc.dom.show = function (element) { element = roc.dom.id(element); element.style.display = ''; return element; }; /** * @method hide 隐藏目标元素 * @param {Element} element 目标元素或目标元素的id * @param {String} element 目标元素 */ roc.dom.hide = function (element) { element = roc.dom.id(element); element.style.display = 'none'; return element; }; /** * @method hasClass 判断元素是否含有 class * @param {Element} el 元素 * @param {String} className class 名称 */ roc.dom.hasClass = function(el, className){ var re = new RegExp('(^|\\s)' + className + '(\\s|$)'); return re.test(el.className); }; /** * @method addClass 给元素添加 class * @param {Element} el 元素 * @param {String} className class 名称 */ roc.dom.addClass = function(el, className){ if(!roc.dom.hasClass(el, className)){ el.className = el.className + ' ' + className; } }; /** * @method removeClass 给元素移除 class * @param {Element} el 元素 * @param {String} className class 名称 */ roc.dom.removeClass = function(el, className){ var re = new RegExp('(^|\\s)' + className + '(?:\\s|$)') el.className = el.className.replace(re, '$1'); }; /** * date对象命名空间 * * @namespace * @name data */ roc.date = roc.date || {}; /** * @method format 对目标日期对象进行格式化 * @param {Object} timestamp 目标日期对象 * @return {String} str 格式化后的时间 */ roc.date.format = function(timestamp) { if(timestamp =='' )return ''; var str = '', temptime = new Date(Number(timestamp)); str += temptime.getFullYear() + '-'; str += temptime.getMonth() + 1 + '-'; str += temptime.getDate() + ' '; str += String(temptime.getHours()).length > 1 ? (temptime.getHours() + ':') : ('0' + temptime.getHours() + ':'); str += String(temptime.getMinutes()).length > 1 ? (temptime.getMinutes()) : ('0' + temptime.getMinutes()); return str; }; /** * cookie对象命名空间 * * @namespace * @name cookie */ roc.cookie = roc.cookie || {}; /** * @method set * @param {String} name cookie的键 * @param {String} value cookie的值 * @param {String} expires 失效时间(小时) * @param {String} domain domain域 * @param {String} path 路径 * @param {String} secure 是否支持https */ roc.cookie.set = function(name, value, expires, domain, path, secure) { var text = encodeURIComponent(value), date = expires; if(date && typeof date === 'number') { date = new Date(); date.setTime(date.getTime() + (expires * 3600000)); } if(date instanceof Date) { text += '; expires=' + date.toUTCString(); } if(domain) { text += '; domain=' + domain; } if(path) { text += '; path=/' + path; } else { text += '; path=/'; } if(secure) { text += '; secure'; } document.cookie = name + '=' + text; }; /** * @method get * @param {String} name cookie的键 */ roc.cookie.get = function(name) { var ret, m; if(name) { if((m = document.cookie.match('(?:^| )' + name + '(?:(?:=([^;]*))|;|$)'))) { ret = m[1] ? decodeURIComponent(m[1]) : ''; } } return ret; }; roc.util = roc.util || {}; roc.util.loger = function( type ,msg ){ switch(type){ case 'pop': alert(msg); break; case 'float':break; default:break; } }; roc.util.resultBlink = function( msg ){ //操作闪烁提示 var $ = roc , opt = $.dom.id("optTip"); $.util.toogle = $.util.toogle || 0; clearTimeout(roc.util.t);//调试 opt.innerHTML = msg ; $.dom.show(opt); opt.className = "blink" + $.util.toogle%2; $.util.toogle++; roc.util.t = setTimeout(function(){ $.dom.hide(opt); },$.config.BLINK_DELAY); }; roc.util.onlyInputNumber = function( id ){ //限制文本框、文本域只能输入数字 var $ = roc , num = $.dom.id( id ); if( num.tagName.toLowerCase() != 'input' || num.tagName.toLowerCase() != 'textarea' ){ return ; } $.util.addEvent( num , 'keypress' , function( e ){ var e = e || window.event ; if(e.keyCode >= 48 && e.keyCode " + "" + " " + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " "; while(!rs.EOF) { var id = num ,//filtRs(rs.Fields("id") ), uaddr = filtRs(rs.Fields("uaddr") ), uphone = filtRs(rs.Fields("uphone") ), typeid = filtRs(rs.Fields("typeid") ), received = filtRs(rs.Fields("received") ), prize = filtRs(rs.Fields("prize") ), unreceived = filtRs(rs.Fields("unreceived") ), installerid = filtRs(rs.Fields("installerid") ), sellerid = filtRs(rs.Fields("sellerid") ), remark = filtRs(rs.Fields("remark") ), selltime = $.date.format(filtRs(rs.Fields("selltime") )), addtime = $.date.format(filtRs(rs.Fields("addtime") ) ); html += "序号 " + "用户地址 " + "用户电话 " + "型号 " + "代收款 " + "货款 " + "余额 " + "安装人 " + "销售电话 " + "备注 " + "销售日期 " + "记录时间 " + "" +" "; //统计项 total_receive += received, total_prize += prize, num++; rs.moveNext(); } html = html +"" + id + " " +"" + uaddr + " " +"" + uphone + " " +"" + typeid + " " +"" + received + " " +"" + prize + " " +"" + unreceived + " " +"" + installerid + " " +"" + sellerid + " " +"" + remark + " " +"" + selltime + " " +"" + addtime + " " +"" +" " +" Σ " +"" +" " +" " + total_receive +" " +"" + total_prize +" " +"" + (total_prize - total_receive ) +" " +"" +" " +" " +" " +" " +""; $.db.closeRs(rs); $.db.closeConn(); return html; }; roc.search.getLock = function(){ //查询锁 if( typeof roc.search.searchLock == 'undefined' ){ roc.search.setLock(false); } return roc.search.searchLock; }; roc.search.setLock = function( key ){ roc.search.searchLock = key; }; //[[id],[type]] roc.search.addEls = [[ "uaddr", "uphone", "typeid", "received", "prize", "unreceived", "installerid", "sellerid", "remark", "selltime" ],[ 'text', 'text', 'num', 'num', 'num', 'num', 'num', 'num', 'text', 'date' ]]; roc.search.insert = function(){ //插入安装单记录 var $ = roc, getV = $.search.getValues( $.search.addEls ); if(!getV){ $.util.loger('pop','请填写信息后再保存!'); return; } var sqlStr = 'insert into inslist (uaddr,uphone,typeid,received,prize,unreceived,installerid,sellerid,remark,selltime) values ('+ getV +')'; $.db.execute( sqlStr ); $.util.resultBlink('保存安装单成功'); }; /*显示与隐藏*/ roc.dom.switchDiv = function( objDiv){ var $ = roc , cookieName = objDiv.id + 'cookie'; if( objDiv.style.display =='' || objDiv.style.display =='none' ){ $.dom.show( objDiv ); $.cookie.set(cookieName,0,9999999); }else{ $.dom.hide( objDiv ); $.cookie.set(cookieName,1,9999999); } }; //货物型号操作 roc.tstyle = roc.tstyle || {}; roc.tstyle.els = [ ['tname','tprize','tdesc'], ['text','text','text'] ]; roc.tstyle.insert = function(){ //插入记录 var $ = roc, getV = $.search.getValues( $.tstyle.els ); if( !getV ){ $.util.loger('pop','请填写信息后再保存!'); return; } var sqlStr = 'insert into type ( tname , tprize , tdesc ) values ('+ getV +')'; //$.util.loger('pop',sqlStr); $.db.execute( sqlStr ); $.util.resultBlink('保存成功!'); $.util.flushInput($.tstyle.els); }; roc.util.flushInput = function( els ){ var $ = roc ; for(var i = 0 ; i 希望本文所述对大家的javascript程序设计有所帮助。
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
相关文章
相关视频
- javascript怎么将值类型强制转为字符串
- javascript中什么是位运算符
- javascript怎么判断字符串是否是数字
- 总结分享: 6 种JavaScript的打断点的方...
- Javascript连接Access数据库完整实例...
- Firebug动态执行JavaScript
- 使用JavaScript
- 使用FireBug调试javascript
- 初识javascript
- 前端开发基础视频-网页的组成html+css+JavaScript
专题推荐
- 独孤九贱-php全栈开发教程
全栈 170W+
主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门
- 玉女心经-web前端开发教程
入门 80W+
主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门
- 天龙八部-实战开发教程
实战 120W+
主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习
- 最新文章
- 热门排行
推荐阅读
-
JS实现可缩放、拖动、关闭和最小化的浮动窗口完整实例_javascript技巧
-
JS实现可缩放、拖动、关闭和最小化的浮动窗口完整实例_javascript技巧
-
js过滤HTML标签完整实例_javascript技巧
-
js过滤HTML标签完整实例_javascript技巧
-
JS实现的简单鼠标跟随DiV层效果完整实例_javascript技巧
-
JavaScript实现的SHA-1加密算法完整实例_javascript技巧
-
js省市联动效果完整实例代码_javascript技巧
-
js省市联动效果完整实例代码_javascript技巧
-
JS实现的简单鼠标跟随DiV层效果完整实例_javascript技巧
-
JavaScript实现的SHA-1加密算法完整实例_javascript技巧
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论