尝试使用 javascript 连接到访问数据库

trying to connect to access database using javascript

我是 javascript 的初学者。我正在尝试借助 javascript 函数连接到访问数据库并编写了以下代码:

<HTML>
<head>
<script>
function AddRecord() 
{
var adoConn = new ActiveXObject("ADODB.Connection");
var adoRS = new ActiveXObject("ADODB.Recordset");
adoConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\TWP Alternate Press.accdb'");
adoRS.Open("Select * From COMMODITIES", adoConn, 1, 2);
console.log('Database Connected');
document.write("c");
adoRS.Close();
adoConn.Close();
}

</script>
</head>
<body>
<input type="button" value="Connect" onclick="AddRecord()">
</body>
</html>

我正在尝试连接到数据库中的 "COMMODITIES" table。但是当我点击 "Connect" 按钮时,没有执行任何操作。我在这里做错了什么。

来自 firebug 我看到以下错误:

ReferenceError: ActiveXObject is not defined    
var adoConn = new ActiveXObject("ADODB.Connection");

我在 Internet Explorer 中也试过了,但是没有打印日志语句。

您正在使用的ActiveXObject,这是微软独有的技术。这意味着此代码片段只能在 Internet Explorer 中运行。由于您提到您使用的是 firebug ,我假设您使用的是 Firefox。

尝试 Internet Explorer 或更好地使用 IndexedDB,它现代、强大、跨浏览器兼容。