欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

java当中JDBC当中请给出一个sql server的stored procedure例子

程序员文章站 2022-07-16 23:24:38
java当中JDBC当中请给出一个sql server的stored procedure例子 ......

3.sql server的stored procedure例子:

import java.sql.*;
public class storedproc0 {
public static void main(string[] args) {
string dburl = "jdbc:jtds:sqlserver://localhost:1433/qixytest";
string user = "sa";
string password = "";

try {
class.forname("net.sourceforge.jtds.jdbc.driver");
connection con = drivermanager.getconnection(dburl, user, password);
system.out.println("connection is ok");
callablestatement cs = con.preparecall("{call all_books}");
resultset rs = cs.executequery();

while(rs.next()){
system.out.println(rs.getstring("bookname") + "\t" +
rs.getstring("authorname") + "\t" +
rs.getint("numbersold"));
}
rs.close();
cs.close();
con.close();

}
catch (exception e) {
e.printstacktrace();
}

文章转载自原文: