0
String call = "{?= CALL Proc(?)}";

CallableStatement cs = conn.prepareCall(call);

cs.registerOutParameter(1, Types.DECIMAL, 0);       
cs.setString(2, "String");
System.out.println(cs);

cs.execute(); // <-- ERROR

First line of simple MySQL procedure:

CREATE DEFINER=`dev`@`11.22.33.44` PROCEDURE `Proc`(IN `login` VARCHAR(255), OUT `var` DECIMAL(20,2) 

.prepareCall turns my CALL into a SELECT (my guess) which mysql considers a Function and gives me a error:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: FUNCTION Proc does not exist

The System.out gives me:

com.mysql.jdbc.JDBC4CallableStatement@38d060ac: SELECT Proc('flavi')

How can I properly call this procedure?

4

1 回答 1

2

尝试更换

String call = "{?= CALL Proc(?)}";

String call = "{CALL Proc(?, ?)}";

前一种语法用于调用您没有的存储函数。你有一个存储过程

您还需要交换绑定参数的顺序,因为参数 1 现在是login字符串,参数 2 是输出变量:

cs.setString(1, "String");
cs.registerOutParameter(2, Types.DECIMAL, 0);       
于 2013-10-15T20:36:47.637 回答