mysql存储过程
mysql 数据库
delimiter //
create procedure selectallstudent() begin select * from tab1;end;//
call selectAllstudent()//
+---------+
| tab1_id |
+---------+
| 0002 |
| 0003 |
| 0004 |
| 0005 |
| 0006 |
+---------+
5 rows in set
Query OK, 0 rows affected
java
package test_procedure; import java.sql.*; public class test_procedure { public static void main(String[] args) { try { Class.forName("com.mysql.jdbc.Driver"); java.sql.Connection conn= DriverManager.getConnection("jdbc:mysql:///trigger", "root", "root"); java.sql.CallableStatement callableStatement=conn.prepareCall("{call selectallstudent()}"); callableStatement.execute(); java.sql.ResultSet resultSet= callableStatement.getResultSet(); while (resultSet.next()) { System.out.println(resultSet.getString(1)); } conn.close(); } catch (Exception e) { e.printStackTrace(); } } }
结果
0002
0003
0004
0005
0006
请留下你的足迹...