jdbcTemplate对oracle存储过程的操作

 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     }

 

转载于:https://www.cnblogs.com/holdouts/articles/5815559.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值