当前位置:Gxlcms > 数据库问题 > 原生jdbc执行存储过程

原生jdbc执行存储过程

时间:2021-07-01 10:21:17 帮助过:2人阅读

//定时任务,结转 . 2 //表名 fys_sch_lvyou2 ,存储过程名:fys_sch_lvyou2_carrayover 3 //无参调用:{call insertLine} 4 //有参调用:{call fys_sch_lvyou2_carrayover(?,?) 然后传递参数即可 5 public void startCarrayOver(){ 6 //获取要结转的时间:当前月(2016年09月30日)的上月,2016年08月 7 Calendar c = Calendar.getInstance(); 8 c.add(Calendar.MONTH, -1); 9 String syear = c.get(Calendar.YEAR)+""; 10 int month = c.get(Calendar.MONTH)+1; 11 String smonth = month<10?"0"+month:month+""; 12 System.out.println("From:"+syear+"-"+smonth); 13 //执行存储过程 14 15 TomcatDataSource tds = SpringBeanUtils.getBean("dataSourceDefault"); 16 Connection conn = null; 17 CallableStatement cs = null; 18 try { 19 conn = tds.getConnection(); 20 cs = conn.prepareCall("{call carryover(?,?)}"); 21 cs.setString(1, syear); 22 cs.setString(2, smonth); 23 cs.execute(); 24 System.out.println("执行存储过程正常!结转成功!"); 25 } catch (SQLException e) { 26 e.printStackTrace(); 27 } finally { 28 try { 29 if (cs!=null) { 30 cs.close(); 31 } 32 if (conn!=null) { 33 conn.close(); 34 } 35 } catch (SQLException e) { 36 e.printStackTrace(); 37 } 38 System.out.println("资源关闭成功!"); 39 } 40 }

 

存储过程详见:oracle函数和存储过程示例

原生jdbc执行存储过程

标签:

人气教程排行