zoukankan      html  css  js  c++  java
  • 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 // -- 定义结束符号

      drop procedure p_test;//

      3、mysql存储过程定义

      以下是代码片段:

      create procedure p_test()

      begin

      declare temp int;

      set temp = 0;

      update test set field1 =temp;

      end

      //

      4、调用方法

      以下是代码片段:

      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存储过程示例的介绍。

     

  • 相关阅读:
    笔试题 易错题目解析
    SqlServer 函数 大全
    视频上传到自己的服务器打不开
    sql 计算生日提请日期
    Web API 异常处理(转)
    微软源代码管理工具TFS2013安装与使用详细图文教程(Vs2013)
    关于枚举的用法和类型转换
    html title换行方法 如a链接标签内title属性鼠标悬停提示内容换行
    JS的parent、opener、self对象
    uploadfiy
  • 原文地址:https://www.cnblogs.com/liuzhuqing/p/7481257.html
Copyright © 2011-2022 走看看