JAVA调用存储过程实例(1)

创建BOOK表

CREATE TABLE BOOK(

ID VARCHAR2(200),
NAME VARCHAR2(200),
describle VARCHAR2(200)

)


创建存储过程

create or replace procedure book_procedure(
v_name in varchar2,
 v_describle varchar2)
is
 v_sql varchar2(200);
v_id_number number(20);
v_id_varchar varchar2(200);
begin
v_sql:='select count(*) from book';
execute immediate v_sql into v_id_number;
v_id_varchar:=to_char(sysdate,'yyyymmdd')||'0000'+v_id_number;
insert into book(id,name,describle) values (v_id_varchar,v_name,v_describle);
end;


dao层调用

//添加
public void addBook(String name,String describle){
try {
this.getJdbcTemplate().execute("call book_procedure('"+name+"','"+describle+"')");
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}


service调用

//添加
public void addBook(String name,String describle){
bookDao.addBook(name, describle);
}

@RequestMapping("/addBook")
public ModelAndView addSerial(HttpServletRequest request) {
String name = request.getParameter("name");
String describle = request.getParameter("describle");
bookService.addBook(name, describle);
return findSerialList(request);
}






展开阅读全文

没有更多推荐了,返回首页