mysql存储过程乱炖

来源:互联网 发布:安信股票交易软件 编辑:程序博客网 时间:2024/05/17 01:26


package test.procedure;


import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Types;


import javax.naming.spi.DirStateFactory.Result;


public class TestProcedure {
public static void main(String args[]) throws ClassNotFoundException, SQLException{
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?noAccessToProcedureBodies=true","root","123456");
CallableStatement callableStatement = connection.prepareCall("{call p(?,?,?)}");
callableStatement.registerOutParameter(3, Types.INTEGER);
callableStatement.setInt(1, 2);
callableStatement.setInt(2, 2);


int result = 0;
callableStatement.setInt(3, result);
callableStatement.execute();

System.out.println(callableStatement.getInt(3));
callableStatement.close();
connection.close();
}
}


delimiter //

create procedure p(in v_a int, v_b int,  out v_ret int)
 begin
 if v_a > v_b then
 set v_ret = v_a;
 else
 set v_ret = v_b;
 end if;
 select v_ret;
 end
 //


http://database.51cto.com/art/201011/235017.htm


http://blog.csdn.net/langzi7758521/article/details/52911796

http://stackoverflow.com/questions/6434573/mysql-execute-command-denied-to-user-localhost-for-routine-error

http://www.cnblogs.com/AloneSword/p/3591702.html

0 0