Connect to and operate Oracle database instances in JavaScript, and use javascriptoracle

Source: Internet
Author: User

Connect to and operate Oracle database instances in JavaScript, and use javascriptoracle

Preface

In the development of B/s and c/s, javascript is basically not used to operate the database. I have confirmed my idea and need to add a large amount of news information to the database. Therefore, I want to obtain information from each rss site and import the information to the database. In fact, I can also choose to use java, c ++, or c # compiling languages. However, using javascript is the most efficient for this job. So why am I happy?

Environment

Operating System: winxp sp2
Use the tool cscript.exe to process files in batches.
Database: oracle 10 Gb as the target database (other databases such as sqlserver, access, and mysql can also be used)
Data access method: ADO (other data access methods, such as odbc and jdbc)

Code:

File Name: rss. js
Copy codeThe Code is as follows:
// Create a database connection object
Var conn = new ActiveXObject ("ADODB. Connection ");
// Create a DataSet object
Var rs = new ActiveXObject ("ADODB. Recordset ");

Try {
// Database connection string, specific configuration, see: http://www.connectionstrings.com/
// If you do not know how to configure the connection string, you can use the text editor to open the UDL file.
Var connectionstring = "Provider = OraOLEDB. Oracle.1; Password = pwd; Persist Security Info = True; User ID = username; Data Source = ORA ";

// Open the connection
Conn. open (connectionstring );

// Query statement
Var SQL = "select * from tb_col ";

// Open the dataset (that is, execute the query statement)
Rs. open (SQL, conn );

// Traverse all records
While (! Rs. eof ){
// WScript is the host object of the Windows Script. For details, see windows Help.
// WScript. Echo output Record Content
WScript. Echo (rs. Fields ("id") + "\ t" + rs. Fields ("name") + "\ n ");

// Next record
Rs. moveNext ();
}

// Close the record set
Rs. close ();
// Close the database connection
Conn. close ();
} Catch (e ){
// Exception report
WScript. Echo (e. message );
} Finally {
//
}

File 2: run. bat

This file is a batch file that runs the rss. js file. Although you can directly run rss. js file, but the file that runs directly is activated using a window. In this case, a window is displayed for each record. So I use the command line method to activate the rss. js file and batch process the command to simplify the command input.
Copy codeThe Code is as follows:
Cscript.exe rss. js
Pause

Run the run. bat file and you can see the result similar to the following:
Copy codeThe Code is as follows:
1 Topic 1

2 Topic 2

3 Topic 3

4 Topic 4

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.