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存储过程示例的介绍。
【编辑推荐】
建立MySQL触发器的语法
配置连接多个mysql服务器的方法
MYSQL BENCHMARK函数的使用
MySQL清除字符串首尾空格函数
MySQL中concat_ws函数的使用
Copyright © 2009-2022 www.wtcwzsj.com 青羊区广皓图文设计工作室(个体工商户) 版权所有 蜀ICP备19037934号