日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > windows >内容正文

windows

oracle windows server 2008,Node.js 在 Windows Server 2008 X64 连接Oracle 数据库

發(fā)布時(shí)間:2025/3/12 windows 14 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle windows server 2008,Node.js 在 Windows Server 2008 X64 连接Oracle 数据库 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

不需要安裝Oralce客戶端,不影響其它使用Oracle客戶端的程序運(yùn)行

安裝Node.JS

node-v12.13.0-x64.msi

安裝VC++ 2013運(yùn)行時(shí)

vcredist_x64.exe

運(yùn)行的版本要與Oracle 客戶端匹配,

下載Oracle 客戶端

instantclient-basiclite-windows.x64-18.5.0.0.0dbru.zip

解壓并放到一個(gè)目錄下:

C:\instantclient_18_5

寫個(gè)Run.bat

REM mynode.bat

SET PATH=C:\instantclient_18_5;%PATH%

node dist/index.js

附源碼

import oracledb from 'oracledb'

import http from 'http'

import urllib from 'url'

import _ from 'lodash'

let md5 = require('md5-node')

const oraConfig = {

connectString :'192.168.*.*:1521/orcl',

user: '****', // 登錄oracle的用戶名

password: '***' // 請(qǐng)換為實(shí)際密碼

}

function doRelease (connection:oracledb.Connection) {

connection.close(

function (err) {

if (err) {

console.error(err.message)

}

})

}

var server:http.Server = http.createServer();

server.on('request', async (request, response)=>{

console.log('收到客戶端的請(qǐng)求了,請(qǐng)求路徑是:' + request.url);

let urlObj = urllib.parse(request.url, true);

if (urlObj.pathname === '/SyncDeviceConfig')

{

response.writeHead(200, { 'Content-Type': 'application/json;charset:utf-8' });

let jsoObj = await GetDeviceConfig(urlObj.query.version_code as string).catch((err)=>{

response.writeHead(406, err.message);

response.end(err);

return;

});

response.end(JSON.stringify(jsoObj));

}

else{

response.writeHead(404, { 'Content-Type': 'text/html' });

response.end('404 Not Found.')

}

});

server.listen(3000, ()=>{

console.log('服務(wù)器啟動(dòng)成功了,可以通過(guò) http://127.0.0.1:3000/ 來(lái)進(jìn)行訪問(wèn)')

})

async function GetDeviceConfig(OldVersionCode :string){

let connection:any;

connection = await oracledb.getConnection(oraConfig)

.catch(err=>{

console.error(err)

throw(err)

});

try

{

let SQL = "select ****";

const V3006 = (await connection.execute(SQL)).rows[0][0];

SQL = "select ****"

const V3007 = (await connection.execute(SQL)).rows[0][0];

SQL = "select *****"

const V3011 = (await connection.execute(SQL)).rows[0][0];

SQL = "select ****"

const V1040 = await connection.execute(SQL);

const mOrgCode = md5(`{"3006":${V3006}, "3007":${V3007}, "1040":[${_.join(V1040.rows.map((m:any)=>`{"NODEID":"${m[0]}","VERSION":${m[1]}}`))}]}`);

if (OldVersionCode === mOrgCode){

throw('already is new vesion!')

}

let jsonObj = {

version_code: mOrgCode,

publishTime : Date.now().toString(),

lines:Array()

};

SQL = `*****`;

let dtLine = await connection.execute(SQL)

jsonObj.lines = dtLine.rows.map( (drLine:any) =>({

lineID:drLine[0], lineName:drLine[2]

}))

for(let lineNode of jsonObj.lines){

lineNode.stations = await FillLineStations(connection, lineNode.lineID)

}

return jsonObj;

}catch(err){

console.error(err);

throw (err)

}finally {

if (connection) {

try {

await connection.close();

} catch (err) {

console.error(err);

}

}

}

}

let FillLineStations = async (connection:oracledb.Connection, LineID:string) =>{

const SQL = `******`;

let dbStations = await connection.execute(SQL)

let r = dbStations.rows?.map((drStation:any)=>({

Node:drStation[0], StationName:drStation[1], IP:drStation[2], Port:drStation[3],

devices:Array.of()

}));

if(r)

{

for(let StationNode of r){

StationNode.devices = await FillStationDevices(connection, StationNode.Node)

}

}

return r;

}

let FillStationDevices = async (connection:any, StationNodeID:string)=>{

const SQL1040 = `*******`;

const V1040 = (await connection.execute(SQL1040, [StationNodeID], { maxRows: 1 } ));

if (V1040 == null || V1040.rows === null || V1040.rows?.length === 0 )

return []

let iv1040 = V1040.rows[0][0];

const SQL_DEVICE = `******`;

let devices = (await connection.execute(SQL_DEVICE))

if (devices.rows)

return devices.rows.map((drDevcie:any)=>({

DeviceCode:drDevcie[4], Node:drDevcie[0], DeviceType:_.trim(drDevcie[1]),IP:drDevcie[2], OS:'', Port:_.toNumber(drDevcie[3])

}))

else

return []

}

總結(jié)

以上是生活随笔為你收集整理的oracle windows server 2008,Node.js 在 Windows Server 2008 X64 连接Oracle 数据库的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。