Foreword
Whether it is b/s or c/s development, JavaScript is basically not used to operate the database. To confirm one of my ideas, I need to add a large amount of news information to the database. Therefore, I want to obtain information from various RSS sites and import the information into the database. In fact, I can also choose to use java, c++, or c# and other compiled languages. However, using javascript language is the most efficient for this work. Then why wouldn’t I do it?
Environment
Operating system: winxp sp2
Tools used: cscript.exe, batch file
Database: oracle 10g as the target database (other databases can also be used, such as: sqlserver, access, mysql, etc.)
Data access method: ADO (other data access methods can also be used, such as: odbc, jdbc, etc.)
Code:
File name: rss.js
try{
//Database connection string, for specific configuration, please refer to: http://www.connectionstrings.com/
//If you don’t know how to configure the connection string, you can get it by configuring the UDL file and opening it with a text editor
var connectionstring = "Provider=OraOLEDB.Oracle.1;Password=pwd;Persist Security Info=True;User ID=username;Data Source=ORA";
//Open connection
conn.open(connectionstring);
//Query statement
var sql = " select * from tb_col ";
//Open the data set (i.e. execute the query statement)
rs.open(sql,conn);
//Traverse all records
while(!rs.eof){
//WScript is the script host object of Windows. For details, please find it in Windows Help.
//WScript.Echo outputs the recorded content
WScript.Echo(rs.Fields("id") "t" rs.Fields("name") "n");
//Next record
rs.moveNext();
}
//Close the record set
rs.close();
//Close database connection
conn.close();
} catch(e){
//Exception report
WScript.Echo(e.message);
} finally{
//
}
File 2: run.bat
This file is a batch file, use this file to run the rss.js file. Although the rss.js file can be run directly, the file that is run directly is activated using a window. The disadvantage is that a window will pop up to display each record. So I used the command line to activate the rss.js file and batched commands to simplify command input.
Run the run.bat file and you will see results similar to the following:
2 Column 2
3 Column 3
4 Column 4