Objective
Whether in the development of B/s or C/s, JavaScript is basically not used to operate the database. And I have a idea that I need to add a lot of news class information to the database, so I want to get the information from each RSS site and import the information into the database. In fact, I can also choose to use java,c++, or C # and other compiled languages, but the use of JavaScript language for this work is the most efficient. What am I going to do about it?
Environment
Operating system: WinXP SP2
Using tools: Cscript.exe, Batch files
Database: Oracle 10g as Target database (you can also use other databases, such as: Sqlserver,access,mysql, etc.)
Data access mode: ADO (You can also use other data access methods, such as: ODBC,JDBC, etc.)
Code:
FileName: rss.js
Copy Code code as follows:
To create a database connection object
var conn = new ActiveXObject ("ADODB. Connection ");
Create DataSet Object
var rs = new ActiveXObject ("ADODB. Recordset ");
try{
Database connection string, specific configuration please refer to: http://www.connectionstrings.com/
If you do not know how to configure a connection string, you can open it by using a text editor after configuring the UDL file
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 a dataset (that is, execute a query statement)
Rs.Open (Sql,conn);
Traverse All records
while (!rs.eof) {
WScript is a script Host object for Windows, please look for details in Windows Help.
WScript.Echo The contents of the output record
WScript.Echo (Rs. Fields ("id") + "\ T" + Rs. Fields ("name") + "\ n");
Next record
Rs.movenext ();
}
Turn off recordsets
Rs.close ();
To close a database connection
Conn.close ();
catch (e) {
Exception Report
WScript.Echo (E.message);
} finally{
//
}
Document II: Run.bat
This file is a batch file that runs the Rss.js file using this file. Although you can run the Rss.js file directly, the file that runs directly is activated using Windows, so there is a bad place where every record pops up a window to display. So I used the command line to activate the Rss.js file and batch commands to simplify the command input.
Copy Code code as follows:
You can see a similar result when you run the Run.bat file:
Copy Code code as follows:
1 column 1
2 column 2
3 Column 3
4 Column 4