日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
java操作mysql存儲過程示例

mysql存儲過程每個DBA都需要掌握的,下面就為您介紹java操作mysql存儲過程的例子,如果您對mysql存儲過程方面感興趣的話,不妨一看。

1、新建表test

 
 
 
  1. create table test(  
  2. field1 int not null  
  3. )  
  4. TYPE=MyISAM ;  
  5. insert into test(field1) values(1); 

2、刪除已存在的存儲過程
-- 刪除儲存過程
delimiter // -- 定義結(jié)束符號
drop procedure p_test;//

3、mysql存儲過程定義

 
 
 
  1. create procedure p_test()  
  2. begin  
  3. declare temp int;  
  4. set temp = 0;   
  5. update test set field1 =temp;  
  6. end  
  7. // 

4、調(diào)用方法

 
 
 
  1. call p_test();  
  2. import java.sql.*;  
  3.  
  4. public class Test Conn{  
  5.  
  6. private Connection getConn(){  
  7. Connection conn = null;  
  8. try {  
  9.    Class.forName("org.gjt.mm.mysql.Driver");  
  10.    try {  
  11.     conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&  
  12.     characterEncoding=GBK","root","ntsky");  
  13.    } catch (SQLException e1) {  
  14.     e1.printStackTrace();  
  15.    }  
  16. }  
  17. catch (ClassNotFoundException e) {  
  18.    e.printStackTrace();  
  19. }  
  20. return conn;   
  21. }  
  22.  
  23. public void testC() {  
  24. Connection conn = getConn();  
  25. ResultSet rs = null;  
  26. CallableStatement cs = null;  
  27. String a = null;  
  28. try {  
  29.    CallableStatement cStmt = conn.prepareCall("{call p_test()}");  
  30.    cStmt.executeUpdate();  
  31. } catch (Exception e) {  
  32.    System.out.println("hahad" + e.getMessage());  
  33. } finally {  
  34.    try {  
  35.     conn.close();  
  36.    } catch (Exception ex) {  
  37.     System.out.println("ex : " + ex.getMessage());  
  38.    }  
  39. }  
  40.  
  41. }  
  42.  
  43. public static void main(String[] args) {  
  44. new TestConn().testC();  
  45. }  
  46. }  

以上java操作mysql存儲過程示例的介紹。

【編輯推薦】

建立MySQL觸發(fā)器的語法

配置連接多個mysql服務(wù)器的方法

MYSQL BENCHMARK函數(shù)的使用

MySQL清除字符串首尾空格函數(shù)

MySQL中concat_ws函數(shù)的使用


文章標題:java操作mysql存儲過程示例
鏈接URL:http://www.dlmjj.cn/article/cdegjee.html