mysql/jdbc function in out param

So i need to run a jdbc call that is going against a sql server database.

CallableStatement cs = conn.prepareCall("{ ? = call "+ spName +" ( ?, ?, ?, ?, ? ) }");

So the sql server call is a function that has output parameters.

we are using mysql database and it looks like mysql functions don't support functions with out put parameters. i tried to see if i could fake out the call using store procs with output parameters but no luck.

any ideas? thanks

 

you're right. mysql doesn't support output parameters on functions, only stored procedures. you'll have to rewrite the function so it only has one return value, or as a procedure where you've moved the return value to an out variable.

public static void testExeFunction() throws Exception { 
Connection conn = CallProcedureRetRS.getConnection(); 
// 创建调用存储过程的预定义SQL语句 
//String sql = "{call testprocedure(?,?,?)}"; 
String sql = "{? = call fun_rpcfunc_varchar()}"; 
//String sql = "{call fun_rpcfunc_varchar(?)}";   //报MYSQL parameter number 1 isnot an OUT parameter错误
try {
 // 创建过程执行器 
CallableStatement cstmt = conn.prepareCall(sql); 
// 设置入参和出参 
cstmt.registerOutParameter(1, Types.VARCHAR); // 注册出参 cstmt.executeUpdate(); 
// 获取输出参数值(两种方式都行)
 //Long id = cstmt.getLong(3); 
// Long id = cstmt.getLong("out_id"); 
String ret = cstmt.getString(1); 
System.out.println("result:=" + ret); 
} catch (SQLException e) { 
e.printStackTrace(); 
} finally {
 } 
} 

 

你可能感兴趣的:(function)