Skip to content

Examples ADODB Connection

Michael Anderson edited this page Dec 12, 2017 · 1 revision

The ActiveX Data Objects driver connects to ActiveX Data Objects file, such as Access (.mdb only) or Excel (.xls only). The adodb driver does not support transactions.

Connection URL

database-js-adodb:///file_path[?parameters]

Usage - Access File

const Connection = require('database-js2').Connection;

var connection = new Connection('adodb:///C:\\Users\\me\\Desktop\\database.mdb');

Select Data from Access

var Connection = require('database-js2').Connection;

(async function() {
    let connection, statement, rows;
    connection = new Connection('adodb:///C:\\Users\\me\\Desktop\\database.mdb');

    try {
        statement = await connection.prepareStatement("SELECT * FROM tablea WHERE user_name = ?");
        rows = await statement.query('not_so_secret_user');
        console.log(rows);
    } catch (error) {
        console.log(error);
    } finally {
        await connection.close();
    }
})();

Select Data from Excel

var Connection = require('database-js2').Connection;

(async function() {
    let connection, statement, rows;
    connection = new Connection('adodb:///C:\\Users\\me\\Desktop\\database.xls?Extended Properties='Excel 8.0;HDR=Yes;IMEX=1';');

    try {
        statement = await connection.prepareStatement("SELECT * FROM [Sheet1$A1:C52] WHERE State = ?");
        rows = await statement.query('South Dakota');
        console.log(rows);
    } catch (error) {
        console.log(error);
    } finally {
        await connection.close();
    }
})();