2、将JDBC解压缩到任意位置,比如解压到C盘programfiles下面,并在安装目录里找到config.default.js文件,得到其路径开始配置环境变量。
3、在环境变量classpath后面追加ProgramFiles、MicrosoftSQLServer2005JDBCDriver、sqljdbc_1.2、enu、sqljdbc。
4、最后连接数据库就可以了。
以连接ORACLE数据库为例:
//创建数据库连接对象var conn = new ActiveXObject("ADODB.Connection")
//创建数据集对象
var rs = new ActiveXObject("ADODB.Recordset")
try{
//如果不知道如何配置连接串,可以通过配置UDL文件后用文本编辑器打开获得
var connectionstring = "Provider=OraOLEDB.Oracle.1Password=pwdPersist Security Info=TrueUser ID=usernameData Source=ORA"
//打开连接
conn.open(connectionstring)
//查询语句
var sql = " select * from tb_col "
//打开数据集(即执行查询语句)
rs.open(sql,conn)
//遍历所有记录
while(!rs.eof){
//WScript是Windows 的脚本宿主对象,详细情况请在windows帮助里查找。
//WScript.Echo输出记录的内容
WScript.Echo(rs.Fields("id") + "\t" + rs.Fields("name") + "\n")
//下一条记录
rs.moveNext() }
//关闭记录集
rs.close()
//关闭数据库连接
conn.close()} catch(e){
//异常报告
WScript.Echo(e.message)} finally{
}
数据库连接串,具体配置请参考:http://www.connectionstrings.com/
报错:Node连接Redis报错 “ClientClosedError: The client is closed”查询资料才发现:Node Redis版本V4之后,连接语法变了。
Starting from v4 of node-redis library, you need to call client.connect() after initializing a client. See this migration guide.
新语法:
const redis = require('redis')
const client = redis.createClient({ socket: { port: 6379 } })
client.connect()
client.on('connect', () =>{
console.log('connected')
})
You might also want to consider running the client connect method with await in an asynchronous function. So you don't have to worry about event listeners.
const redis = require('redis')
(async () =>{
try {
const client = redis.createClient({ socket: { port: 6379 } })
await client.connect()
console.log('connected')
} catch (err) {
console.error(err)
}
})()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[Example]:
const redis = require("redis")
(async () =>{
try {
const client = redis.createClient({
socket: { port: 6379 },
legacyMode: true,
})
await client.connect()
console.log("connected")
await client.v4.set("key4", "value2", {
NX: true,
})
client.set("key3", "value3", "NX", (err, reply) =>{})
await client.get("key4", function (err, v) {
console.log("redis get hello err,v", err, v)
})
client.set("student1", "Laylaa1", function (err, reply) {
if (err) {
console.log(err)
callback(err, null)
return
}
console.log(reply)
})
} catch (err) {
console.error(err)
}
})()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)