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();
}

文章转载自原文:https://blog.csdn.net/qq_44594249/article/details/100666192

你可能感兴趣的:(java当中JDBC当中请给出一个sql server的stored procedure例子)