1
import java.sql.*;
2
3
public class ProcedureTest {
4
public static void main(String args[]) throws Exception {
5
//加載驅動
6
DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
7
//獲得連接
8
Connection conn = DriverManager.getConnection("jdbc:odbc:mydata", "sa",
9
"");
10
Statement stmt = conn.createStatement();
11
//在JAVA中創建存儲過程
12
stmt.executeUpdate("create procedure OOP as select * from 學生成績表");
13
CallableStatement c = conn.prepareCall("{call OOP}");
14
ResultSet rs = c.executeQuery();
15
while (rs.next()) {
16
String chinese = rs.getString("Chinese");
17
System.out.println(chinese);
18
}
19
conn.close();
20
}
21
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21
