本文介绍了JDBC存储过程调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个存储过程如下:
I created a stored procedure as follows:
//mysql中的存储过程
//Stored procedures in mysql
DELIMITER $$ CREATE PROCEDURE `bank`.`hello` (in id varchar(20),in pass varchar(20)) BEGIN insert into admin(username,password) values (id,pass); END $$ DELIMITER ;我在java中调用存储过程如下:
and I am calling the stored procedure in java as follows:
//使用JDBC调用存储过程
//calling stored procedures using JDBC
package StoredProcEx; import java.sql.*; public class StoredProcEx { public static void main(String arg[]){ try{ Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bank","root","root"); //PreparedStatement stmt=con.prepareStatement("insert into admin values(?,?)"); CallableStatement stmt=con.prepareCall("{?=call hello(?,?)}"); stmt.setString(1,"birender"); stmt.setString(2,"admin"); stmt.execute(); //stmt.execute(); } catch(ClassNotFoundException ce){ ce.printStackTrace(); } catch(SQLException se){ se.printStackTrace(); } catch(Exception e){} } }但它显示如下编译时异常:
But it is showing a compile time exception as follows:
可以为存储的函数调用的返回值设置 IN 参数.
Can's set IN parameter for return value of stored function call.
推荐答案请使用
CallableStatement stmt=con.prepareCall("{call hello(?,?)}");代替
CallableStatement stmt=con.prepareCall("{?=call hello(?,?)}");首先?在您的代码中用于返回类型
First ? in your code is used for return type
更多推荐
JDBC存储过程调用
发布评论