1 @Autowired 2 JdbcTemplate jdbcTemplate; 3 4 /** 5 * 仅仅有输入参数 6 */ 7 public void testev() { 8 String uuid = UUID.randomUUID().toString(); 9 this.jdbcTemplate.execute("call testproce('" + uuid + "','wang')"); 10 System.out.println("success"); 11 } 12 13 /** 14 * 有输入参数和输出参数 15 */ 16 public void testout() { 17 @SuppressWarnings({ "rawtypes", "unchecked" }) 18 String parament = (String) this.jdbcTemplate.execute(new CallableStatementCreator() { 19 20 public CallableStatement createCallableStatement(Connection con) throws SQLException { 21 // String storedProc = "{call sp_select_table (?,?)}";// 调用的sql 22 String exeProce = "{call test_in_pro(?,?)}"; 23 CallableStatement csCallableStatement = con.prepareCall(exeProce); 24 csCallableStatement.setString(1, "sss"); 25 csCallableStatement.registerOutParameter(2, OracleTypes.VARCHAR); 26 return csCallableStatement; 27 } 28 }, new CallableStatementCallback() { 29 public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException { 30 cs.execute(); 31 return cs.getString(2); 32 } 33 }); 34 System.out.println(parament); 35 } 36 //list类型的参数的获取 37 @Test 38 public void testinout() { 39 @SuppressWarnings({ "unchecked", "rawtypes" }) 40 List listdata = (List) this.jdbcTemplate.execute(new CallableStatementCreator() { 41 42 public CallableStatement createCallableStatement(Connection con) throws SQLException { 43 String exeProcStr = "call listtest(?,?)"; 44 CallableStatement csCallableStatement = con.prepareCall(exeProcStr); 45 csCallableStatement.setString(1, "王立虎"); 46 csCallableStatement.registerOutParameter(2, OracleTypes.CURSOR); 47 return csCallableStatement; 48 } 49 }, new CallableStatementCallback() { 50 51 public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException { 52 List list = new ArrayList(); 53 cs.execute(); 54 ResultSet resultSet = (ResultSet) cs.getObject(2); 55 while (resultSet.next()) { 56 Map resuMap = new HashMap(); 57 resuMap.put("id", resultSet.getString("userinfo_id")); 58 resuMap.put("name", resultSet.getString("userinfo_name")); 59 list.add(resuMap); 60 } 61 resultSet.close(); 62 return list; 63 } 64 65 }); 66 67 for (Object object : listdata) { 68 Map rowmap = (Map) object; 69 String name = rowmap.get("name").toString(); 70 String id = rowmap.get("id").toString(); 71 System.out.println(id + name); 72 } 73 74 }