一、基本語句,剩下的自己組合。
ALTER proc getStudentNum(@param nvarchar(50),@StuNum int output) as select @StuNum=count(*) from BASE_LOG_INFO where CREATEOPER=@param
1、語句結構,上面那個就是
2、寫參數測試
3、結果
二、Java調用
import java.sql.*; public Map getEventComplete(HttpServletRequest request) { String orgid = StringUtil.getStringValue(map.get("orgid")); Map<String,Object> resultMap = new HashMap<>(); //查詢事件上報總數 Map<String, ?> stringMap = new ExtendEvent(RequestUtil.getMap(request)).countEventNum(); Map<String,String> yblMap = new HashMap<>(); Object data = stringMap.get("data"); Object total = ((HashMap) ((ArrayList) data).get(0)).get("total"); //數據庫等配置 String username = PropertyUtil.getPropertyValue("jdbc.properties", "jdbc.username"); String password = PropertyUtil.getPropertyValue("jdbc.properties", "jdbc.password"); String url = PropertyUtil.getPropertyValue("jdbc.properties", "jdbc.url"); String driver = PropertyUtil.getPropertyValue("jdbc.properties", "jdbc.driverClassName"); Connection dbConn = null; CallableStatement stmt = null; try { //開始調用調用存儲過程 Class.forName(driver); dbConn = DriverManager.getConnection(url, username, password); //所有的輸入+輸出參數。 String call= "{call bigscreen_eventfulfil_ybj(?,?,?,?)}; "; stmt = dbConn.prepareCall(call);// 調用存儲過程 //寫參數下標,從1開始,一共四個參數 stmt.setString(1,orgid); stmt.registerOutParameter(2,Types.VARCHAR); //聲明輸出參數是什么類型的 stmt.registerOutParameter(3,Types.VARCHAR); //聲明輸出參數是什么類型的 stmt.registerOutParameter(4,Types.VARCHAR); //聲明輸出參數是什么類型的 stmt.execute(); String today_num=stmt.getString(2); //獲得輸出參數2 String week_num=stmt.getString(3);//獲得輸出參數3 String month_num=stmt.getString(4);//獲得輸出參數4 } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } //關閉 finally { try { if(stmt!=null){ stmt.close();} if(dbConn!=null){dbConn.close();} } catch (SQLException e) { e.printStackTrace(); } } //事件上報總數 resultMap.put("eventTotal",total); return resultMap; }