Home > Web Front-end > JS Tutorial > Connection operation of Oracle database instance in JavaScript_javascript skills

Connection operation of Oracle database instance in JavaScript_javascript skills

WBOY
Release: 2016-05-16 16:06:16
Original
3579 people have browsed it

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

Copy code The code is as follows:

//Create database connection object
var conn = new ActiveXObject("ADODB.Connection");
//Create data set object
var rs = new ActiveXObject("ADODB.Recordset");

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.

Copy code The code is as follows:

cscript.exe rss.js
pause

Run the run.bat file and you will see results similar to the following:

Copy code The code is as follows:

1 Column 1

2 Column 2

3 Column 3

4 Column 4

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template