JS读取ACCESS数据库类,已封装
来源:互联网 发布:和外国高中生恋爱知乎 编辑:程序博客网 时间:2024/06/06 22:44
// JavaScript Document
/*
javascript操作ACCESS数据库类
程序名:jsaccess.js
适用:windows环境下,IE浏览器
by adengou 2015.11.20
*/
/*基本参数
rs.Fields.Count//表中字段数量
rs.Fields(i).name//第i个字段名称
rs.Fields(i).vale//第i个字段值
rs.recordcount//数据库记录总数
*/
(function(){
var _JSACCESS ={};
/// 建立数据库连接
_JSACCESS.conn=function(dbfFilePath){
try{
var conn = new ActiveXObject("ADODB.Connection");
var conStr ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+dbfFilePath+" ";
//var conStr ="DBQ="+dbfFilePath+";DRIVER={Microsoft Access Driver (*.mdb)};";
conn.open(conStr);//conn.Open(conStr);
return conn;
}catch(e){
alert(e.description);
return null;
}
}
///定义RS
_JSACCESS.rs =function(){
var rs = new ActiveXObject("ADODB.Recordset") ;
rs.CursorType = 1;
rs.CursorLocation = 2;
rs.LockType = 3;//可读可写模式
return rs;
}
//关闭数据库
_JSACCESS.closeDB =function(conn,rs){
rs.close();
rs = null;
conn.close();
conn = null;
}
//查询记录
_JSACCESS.query = function(dbfFilePath,sql){
var conn = this.conn(dbfFilePath);
if(conn==null){return "";}
var rs = this.rs();
//
rs.open(sql, conn);
var str ="";
var arrData =new Array();
while(!rs.EOF&&!rs.BOF){
str ="{";
for(var i=0;i<rs.Fields.Count;i++){
str +="\""+rs.Fields(i).name+"\""+":"+"\""+rs.Fields(i).value+"\"";
str +=",";
}
str +="}";
arrData.push(str);
rs.moveNext;
}
this.closeDB(conn,rs);//关闭数据库
return arrData;//返回JSSON 数据 接收用 var receiveData =eval("("+arrData[0]+")");来解析
}
//获取数据库记录总数
_JSACCESS.getDataCount = function(dbfFilePath,sql){
var conn = this.conn(dbfFilePath);
if(conn==null){return 0;}
var rs = this.rs();
rs.open(sql, conn);
var count =rs.recordcount;
this.closeDB(conn,rs);
return count;
}
///增加记
_JSACCESS.insert =function(dbfFilePath,sql){
var conn =this.conn(dbfFilePath);
if(conn==null){ alert("数据库连接不成功!");return false;}
//
// sql="insert into addresslist(name,department,cellphone) values('name','department','13xxxxxxxxxx')";
try{
conn.execute(sql);
conn.close();
conn =null;
return true;
}catch(e){
alert("error_insert:"+e.message);
conn.close();
conn =null;
return false;
}
}
///修改记录
_JSACCESS.modify =function(dbfFilePath,sql){
var conn =this.conn(dbfFilePath);
if(conn==null){return false;}
// sql="update addresslist set name='name' where id=2";
try{
conn.execute(sql);
conn.close();
conn =null;
return true;
}catch(e){
alert("error_modify:"+e.message);
conn.close();
conn =null;
return false;
}
}
//
///删除记录
_JSACCESS.del =function(dbfFilePath,sql){
var conn =this.conn(dbfFilePath);
if(conn==null){return false;}
// sql="delete * from addresslist where id=2";
try{
conn.execute(sql);
conn.close();
conn =null;
return true;
}catch(e){
alert("error_del:"+e.message);
conn.close();
conn =null;
return false;
}
}
//
window["_JSACCESS"]=_JSACCESS;
})();
/*
javascript操作ACCESS数据库类
程序名:jsaccess.js
适用:windows环境下,IE浏览器
by adengou 2015.11.20
*/
/*基本参数
rs.Fields.Count//表中字段数量
rs.Fields(i).name//第i个字段名称
rs.Fields(i).vale//第i个字段值
rs.recordcount//数据库记录总数
*/
(function(){
var _JSACCESS ={};
/// 建立数据库连接
_JSACCESS.conn=function(dbfFilePath){
try{
var conn = new ActiveXObject("ADODB.Connection");
var conStr ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+dbfFilePath+" ";
//var conStr ="DBQ="+dbfFilePath+";DRIVER={Microsoft Access Driver (*.mdb)};";
conn.open(conStr);//conn.Open(conStr);
return conn;
}catch(e){
alert(e.description);
return null;
}
}
///定义RS
_JSACCESS.rs =function(){
var rs = new ActiveXObject("ADODB.Recordset") ;
rs.CursorType = 1;
rs.CursorLocation = 2;
rs.LockType = 3;//可读可写模式
return rs;
}
//关闭数据库
_JSACCESS.closeDB =function(conn,rs){
rs.close();
rs = null;
conn.close();
conn = null;
}
//查询记录
_JSACCESS.query = function(dbfFilePath,sql){
var conn = this.conn(dbfFilePath);
if(conn==null){return "";}
var rs = this.rs();
//
rs.open(sql, conn);
var str ="";
var arrData =new Array();
while(!rs.EOF&&!rs.BOF){
str ="{";
for(var i=0;i<rs.Fields.Count;i++){
str +="\""+rs.Fields(i).name+"\""+":"+"\""+rs.Fields(i).value+"\"";
str +=",";
}
str +="}";
arrData.push(str);
rs.moveNext;
}
this.closeDB(conn,rs);//关闭数据库
return arrData;//返回JSSON 数据 接收用 var receiveData =eval("("+arrData[0]+")");来解析
}
//获取数据库记录总数
_JSACCESS.getDataCount = function(dbfFilePath,sql){
var conn = this.conn(dbfFilePath);
if(conn==null){return 0;}
var rs = this.rs();
rs.open(sql, conn);
var count =rs.recordcount;
this.closeDB(conn,rs);
return count;
}
///增加记
_JSACCESS.insert =function(dbfFilePath,sql){
var conn =this.conn(dbfFilePath);
if(conn==null){ alert("数据库连接不成功!");return false;}
//
// sql="insert into addresslist(name,department,cellphone) values('name','department','13xxxxxxxxxx')";
try{
conn.execute(sql);
conn.close();
conn =null;
return true;
}catch(e){
alert("error_insert:"+e.message);
conn.close();
conn =null;
return false;
}
}
///修改记录
_JSACCESS.modify =function(dbfFilePath,sql){
var conn =this.conn(dbfFilePath);
if(conn==null){return false;}
// sql="update addresslist set name='name' where id=2";
try{
conn.execute(sql);
conn.close();
conn =null;
return true;
}catch(e){
alert("error_modify:"+e.message);
conn.close();
conn =null;
return false;
}
}
//
///删除记录
_JSACCESS.del =function(dbfFilePath,sql){
var conn =this.conn(dbfFilePath);
if(conn==null){return false;}
// sql="delete * from addresslist where id=2";
try{
conn.execute(sql);
conn.close();
conn =null;
return true;
}catch(e){
alert("error_del:"+e.message);
conn.close();
conn =null;
return false;
}
}
//
window["_JSACCESS"]=_JSACCESS;
})();
0 0
- JS读取ACCESS数据库类,已封装
- ACCESS数据库访问类封装
- 使用CDatabase类读取Access数据库
- Javascript读取ACCESS数据库
- qt4:读取 access 数据库
- qt4:读取 access 数据库
- php读取Access数据库
- java 读取 access数据库
- asp读取access数据库
- Python读取access数据库
- ___71__OleDbDataReader读取Access数据库
- 封装读取数据库
- NET access连接数据库封装
- js事件封装(已兼容)
- 封装ASP.NET操作ACCESS数据库常用操作的类
- 封装ASP.NET操作ACCESS数据库常用操作的类
- 数据库操作的封装的类 对Access操作
- C#.NET万能数据库访问封装类(ACCESS、SQLServer、Oracle)
- Redis 或弃用当前 VM 机制,采用新的 diskstore 模型
- 去掉点击出现的透明阴影--&&--去除iphone、ipad页面button默认样式--元素垂直居中
- MySQL 中 GROUP BY 基本实现原理
- Exception in thread "main" java.lang.NoClassDefFoundError: javax/transaction/Synchronization
- libcur+openssl的编译和使用
- JS读取ACCESS数据库类,已封装
- xcode 也有atom 装逼插件activate-power-mode
- oracle 中 in 和exists用法区别
- 再按一次退出程序
- jquery 滚动条分页加载数据
- Opencv 给图像添加边界
- listView的几个重要的属性
- MIRO/MIR7有何差别
- 跨平台(windows和unix系列)读写锁