js怎样调用存储过程?

JavaScript08

js怎样调用存储过程?,第1张

JDBC调用存储过程:CallableStatement 在Java里面调用存储过程,写法那是相当的固定: Class.forName(.... Connectionconn=DriverManager.getConnection(.... /** *p是要调用的存储过程的名字,存储过程的4个参数,用4个?号占位符代替 *其余地方写法固定 */ CallableStatementcstmt=conn.prepareCall("{callp(?,?,?,?)}")/** *告诉JDBC,这些个参数,哪些是输出参数,输出参数的类型用java.sql.Types来指定 *下面的意思是,第3个?和第4个?是输出参数,类型是INTEGER的 *Types后面具体写什么类型,得看你的存储过程参数怎么定义的 */ cstmt.registerOutParameter(3,Types.INTEGER)cstmt.registerOutParameter(4,Types.INTEGER)/** *p是要调用的存储过程的名字,存储过程的4个参数,用4个?号占位符代替 *其余地方写法固定 */ CallableStatementcstmt=conn.prepareCall("{callp(?,?,?,?)}")/** *在我这里第1个?和第2个?是输入参数,第3个是输出参数,第4个既输入又输出 *下面是设置他们的值,第一个设为3,第二个设为4,第4个设置为5 *没设第3个,因为它是输出参数 */ cstmt.setInt(1,3)cstmt.setInt(2,4)cstmt.setInt(4,5)//执行 cstmt.execute()//把第3个参数的值当成int类型拿出来 intthree=cstmt.getInt(3)System.out.println(three)//把第4个参数的值当成int类型拿出来 intfour=cstmt.getInt(4)System.out.println(four)//用完别忘给人家关了,后开的先关 cstmt.close()conn.close() JDBC调用存储过程,掌握这一个程序足够了. 以下是上面程序使用的存储过程的代码,我用的是Oracle数据库,不过不论是什么数据库,对于你的程序,JDBC这一端写法都是一样的. createorreplaceprocedurep (v_ainnumber,v_bnumber,v_retoutnumber,v_tempinoutnumber) is begin if(v_a>v_b)then v_ret:=v_a else v_ret:=v_b endif v_temp:=v_temp 1end

node.js访问sqlserver 使用mssql模块。

地址:"https://github.com/patriksimek/node-mssql

var mssql =require("mssql")

--------------------

sql.connect(config, function (err) {

if (err) {

return callback(err)

}

var request = new sql.Request()

// request.input('stuName', sql.VarChar(50),stuName)

// request.input('age', sql.Int,parseInt(age))

request.execute('usp_SelectStudentsAll', function (err, recordsets, returnValue) {

if (err) {

return callback(err)

}

console.log(recordsets.length)// count of recordsets returned by the procedure

console.log(recordsets[0].length)// count of rows contained in first recordset

console.log(returnValue)// procedure return value

console.log(recordsets.returnValue)// same as previous line

callback(err, recordsets, returnValue)

})

})