1. 程式人生 > >mysql存儲過程及(java調用)

mysql存儲過程及(java調用)

mysql 存儲過程

create procedure DeleteDataByPdfDocId
(
   IN pdfDocId varchar(100)
)
BEGIN
#根據pdfDocId刪除數據
DELETE FROM pdf_formula WHERE PDF_DOCID = pdfDocId ;
DELETE FROM pdf_image WHERE PDF_DOCID = pdfDocId ;
DELETE FROM pdf_table WHERE PDF_DOCID = pdfDocId ;
DELETE FROM pdf_paragraph WHERE PDF_DOCID = pdfDocId ;
DELETE FROM pdf_addendum_section WHERE PDF_DOCID = pdfDocId ;
DELETE FROM pdf_addendum_chapter WHERE PDF_DOCID = pdfDocId ;
DELETE FROM pdf_addendum WHERE PDF_DOCID = pdfDocId ;
DELETE FROM pdf_section WHERE PDF_DOCID = pdfDocId ;
DELETE FROM pdf_backcover WHERE PDF_DOCID = pdfDocId ;
DELETE FROM pdf_catalog WHERE PDF_DOCID = pdfDocId ;
DELETE FROM pdf_chapter WHERE PDF_DOCID = pdfDocId ;
DELETE FROM pdf_coverpage WHERE PDF_DOCID = pdfDocId ;
DELETE FROM pdf_descriptioin_info WHERE PDF_DOCID = pdfDocId ;
DELETE FROM pdf_foreword WHERE PDF_DOCID = pdfDocId ;
DELETE FROM pdf_introduction WHERE PDF_DOCID = pdfDocId ;
DELETE FROM pdf_maintext WHERE PDF_DOCID = pdfDocId ;
DELETE FROM pdf_modify_details WHERE PDF_DOCID = pdfDocId ;
DELETE FROM pdf_reference_doc WHERE PDF_DOCID = pdfDocId ;
DELETE FROM standard_formal_catalogstructure WHERE PDF_DOCID = pdfDocId ;
DELETE FROM standard_formal_element WHERE PDF_DOCID = pdfDocId ;
DELETE FROM standard_samples_notes WHERE PDF_DOCID = pdfDocId ;
DELETE FROM pdf_document WHERE id = pdfDocId;
DELETE FROM lkstcs_operations_log WHERE PDF_DOCID = pdfDocId;
DELETE FROM standard_complie_record WHERE PDF_DOCID = pdfDocId ;
END
create procedure UpdatePdfElementStdNo
(
   IN stdNo varchar(1000),
   IN oldStdNo varchar(1000)
)
BEGIN
#更新標準號
UPDATE pdf_addendum SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
UPDATE pdf_addendum_chapter SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
UPDATE pdf_addendum_section SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
UPDATE pdf_backcover SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
UPDATE pdf_catalog SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
UPDATE pdf_chapter SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
UPDATE pdf_coverpage SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
UPDATE pdf_descriptioin_info SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
UPDATE pdf_foreword SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
UPDATE pdf_formula SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
UPDATE pdf_image SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
UPDATE pdf_introduction SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
UPDATE pdf_maintext SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
UPDATE pdf_modify_details SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
UPDATE pdf_paragraph SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
UPDATE pdf_reference_doc SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
UPDATE pdf_section SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
UPDATE pdf_table SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
UPDATE standard_formal_catalogstructure SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
UPDATE standard_formal_element SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
UPDATE pdf_document SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
UPDATE standard_complie_record SET STANDARD_NO = stdNo WHERE STANDARD_NO = oldStdNo;
END


以上兩段代碼為更新和刪除數據的存儲過程,

調用:

public void update(String sNo1, String sNo2) {

String updateSQL= "{call UpdatePdfElementStdNo(?,?)}";//存儲過程的名字

getSession().createSQLQuery(updateSQL).setString(0, sNo1).setString(1, sNo2).executeUpdate();

}

本文出自 “shihou” 博客,謝絕轉載!

mysql存儲過程及(java調用)