新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
java操作mysql存儲過程示例
mysql存儲過程每個DBA都需要掌握的,下面就為您介紹java操作mysql存儲過程的例子,如果您對mysql存儲過程方面感興趣的話,不妨一看。

1、新建表test
- create table test(
- field1 int not null
- )
- TYPE=MyISAM ;
- insert into test(field1) values(1);
2、刪除已存在的存儲過程
-- 刪除儲存過程
delimiter // -- 定義結(jié)束符號
drop procedure p_test;//
3、mysql存儲過程定義
- create procedure p_test()
- begin
- declare temp int;
- set temp = 0;
- update test set field1 =temp;
- end
- //
4、調(diào)用方法
- call p_test();
- import java.sql.*;
- public class Test Conn{
- private Connection getConn(){
- Connection conn = null;
- try {
- Class.forName("org.gjt.mm.mysql.Driver");
- try {
- conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&
- characterEncoding=GBK","root","ntsky");
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- }
- catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- return conn;
- }
- public void testC() {
- Connection conn = getConn();
- ResultSet rs = null;
- CallableStatement cs = null;
- String a = null;
- try {
- CallableStatement cStmt = conn.prepareCall("{call p_test()}");
- cStmt.executeUpdate();
- } catch (Exception e) {
- System.out.println("hahad" + e.getMessage());
- } finally {
- try {
- conn.close();
- } catch (Exception ex) {
- System.out.println("ex : " + ex.getMessage());
- }
- }
- }
- public static void main(String[] args) {
- new TestConn().testC();
- }
- }
以上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


咨詢
建站咨詢
