JavaWeb笔记15-JDBC调用存储过程和存储函数

JDBC模板总结
1、导入驱动包、加载具体驱动类

Class.forName("com.jdbc.mysql.Driver");

2、与数据库建立链接

Connection conn=DriverManager.getConnection(connectionUrl,userName,passWord);

3、通过连接connection获取操作数据库的对象(Statement/PreparedStatement)

PreparedStatement pstmt=conn.PrepareStatement(sql);

4、(查询)处理结果集,循环输出

ResultSet rs=pstmt.executeQuery();

5、关闭结果集/数据库

rs.close();
conn.close();

CallableStatement
调用存储过程、存储函数
调用方法:

connection.prepareCall(存储过程或存储函数名);

参数格式:
(1)参数为存储过程(无返回值,用Out参数代替):
{call 存储过程名(参数列表)}
(2)参数为存储函数(有返回值return):
{?=call 存储函数名(参数列表) }


版权声明:本文为PIUYIXIU原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。