http://xiangai.taobao.com
http://shop148612228.taobao.com

连接sqlServer数据库&jpa调用存储过程Java获取存储过程返回的多个结果集JAVA调用sqlserver存储过程的实现(返回多个结果集的实现)jdbc多结果集(getMoreResults)

存储过程:

  1. BEGIN  
  2. select * from teacher;  
  3. SELECT * FROM student;
  4. END  
public Object GetMyBOProjectProductList(@PathVariable(value = "userid") int userid) {

String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String url = "jdbc:sqlserver://10.110.110.110:1433;DatabaseName=B2BAug";
Connection conn = null;
CallableStatement cs = null;// PreparedStatement,Statement
//ResultSet rs;

try {
Class.forName(driver);
conn = DriverManager.getConnection(url, "sa", "1234%abc");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}

try {
cs = conn.prepareCall("{call UP_GetMyPuctList(?)}");
cs.setString(1, "" + userid);
boolean flag = cs.execute();
ResultSet rs = cs.getResultSet();

while (rs != null && rs.next()) {
System.out.println("ID:" + rs.getString(1));
}
if (cs.getMoreResults()) {
rs = cs.getResultSet();
while (rs != null && rs.next()) {
System.out.println("ID:" + rs.getString(1));
}
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (cs != null)
cs.close();
if (conn != null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}


return userid;
}


参考文档:
http://www.mamicode.com/info-detail-1697679.html
https://blog.csdn.net/ruiguang21/article/details/77890372
https://blog.csdn.net/zmhzhangminhua/article/details/38704281
http://arthur-3726.iteye.com/blog/438700
posted @ 2018-07-31 14:26  万事俱备就差个程序员  阅读(747)  评论(0编辑  收藏  举报

http://xiangai.taobao.com
http://shop148612228.taobao.com
如果您觉得对您有帮助.领个红包吧.谢谢.
支付宝红包
微信打赏 支付宝打赏