zoukankan      html  css  js  c++  java
  • mysql函数

    1、创建函数

    #创建函数
    create function fun_add(x1 int,x2 int) returns INT	
    	begin 
    		return x1 + x2;
    	end
    #查看函数
    show function status;
    show function status like '%add%'
    #调用函数
    select fun_add(1,2)

    2、Java调用函数

     @org.junit.Test
        public void testfun_add() throws Exception {
            long start = System.currentTimeMillis();
            //创建连接
            String driverClass = "com.mysql.jdbc.Driver";
            String url = "jdbc:mysql://localhost:3306/mysql_jdbc";
            String username = "root";
            String password = "root";
            Class.forName(driverClass);
            Connection con = DriverManager.getConnection(url, username, password);
            //关闭自动提交
            con.setAutoCommit(false);
            //调用存储过程
            CallableStatement cst = con.prepareCall("{? = call fun_add(?,?)}");
            //设置输入参数
            cst.setInt(2,100);
            cst.setInt(3,300);
            cst.registerOutParameter(1,Types.INTEGER);
            //执行存储过程
            cst.execute();
            int result = cst.getInt(1);
            System.out.println(result);
            //提交
            con.commit();
    
            cst.close();
            con.close();
            long time = System.currentTimeMillis() - start;
            System.out.println(time);//2085
        }
    

    欢迎关注我的公众号:小秋的博客 CSDN博客:https://blog.csdn.net/xiaoqiu_cr github:https://github.com/crr121 联系邮箱:rongchen633@gmail.com 有什么问题可以给我留言噢~
  • 相关阅读:
    C/C++中0xcccccccc...
    函数指针定义
    Visual C++的DLL
    RGB
    链接指示:extern "C"
    for_each用法
    漫画 | 夜深了,程序员的电脑却没关,发生了这样的故事…
    漫画 | 小公司卧薪尝胆三年,意外拿到美团offer
    Java 可变参数
    使用程序往Neo4j导入CSV报错
  • 原文地址:https://www.cnblogs.com/flyingcr/p/10326905.html
Copyright © 2011-2022 走看看