JDBC存储过程调用

编程入门 行业动态 更新时间:2024-10-25 18:25:22
本文介绍了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存储过程调用

本文发布于:2023-10-26 09:26:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529762.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:存储过程   JDBC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!