JavaScript connection operation Oracle database instance _javascript tips

Source: Internet
Author: User

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:

Cscript.exe Rss.js
Pause

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

Related Article

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.