These operations may not be used, but they are also posted. There are also many related examples on the Internet. I will not post a new article on my own. please correct me.
Note:
Under the directory where the HTML file is stored, there is a subdirectory for storing the database: webdata, where the database name is scdata. MDB
The database has a userlist table with two fields, userid and username, and a test data with userid = '20170101' and username = 'smallcol '.
JS Code:
File scengine. js
// Database-like connection pool
Function scdbpool (){
Try {
This. Con = new activexobject ("ADODB. Connection ");
This. Con. provider = "Microsoft. Jet. oledb.4.0 ";
This. rs = new activexobject ("ADODB. recordset ");
} Catch (e ){
This. Con = NULL;
This. rs = NULL;
}
This. filepath = NULL;
This. dbpath = NULL;
};
// Set the relative path of the database file (locate the file) and the database name
Scdbpool. Prototype. setdb = function (dbpath ){
This. dbpath = dbpath;
};
// Set the database location file. This step can be included in the connection class. Here, the database is written to facilitate the use of any name.
Scdbpool. Prototype. setdbpathposition = function (urlfile ){
VaR filepath = location. href. substring (0, location. href. indexof (urlfile ));
This. dbpath = (this. dbpath = NULL | this. dbpath = "")? "/Webdata/scdata. mdb": This. dbpath;
VaR Path = filepath + this. dbpath;
// Remove the "files: //" string before the path
This. filepath = path. substring (8 );
};
// Establish a connection with the database
Scdbpool. Prototype. Connect = function (){
This. Con. connectionstring = "Data Source =" + this. filepath;
This. Con. open;
};
// Execute the database statement and return the result set
Scdbpool.prototype.exe cutequery = function (SQL ){
This. Rs. Open (SQL, this. Con );
};
// No result set is returned when database statements are executed.
Scdbpool.prototype.exe cute = function (SQL ){
This.con.exe cute (SQL );
};
// Close the result set
Scdbpool. Prototype. rsclose = function (){
This. Rs. Close ();
This. rs = NULL;
};
// Close the data connection
Scdbpool. Prototype. conclose = function (){
This. Con. Close ();
This. Con = NULL;
};
HTML file. The page aa.html is the relative location file of the database.
<Script language = "JavaScript">
VaR DB = new scdbpool ();
DB. setdbpathposition ("aa.html ");
DB. Connect ();
VaR SQL = "select * from [userlist] Where userid = '000000 '";
Db.exe cutequery (SQL );
While (! DB. Rs. EOF ){
VaR CNT = dB. Rs. Fields ("username ");
Document. Write (CNT );
DB. Rs. movenext;
}
DB. rsclose ();
DB. conclose ();
</SCRIPT>
The above is for my personal reference. please correct me if there is any error. Thank you. I am Continuously learning.