---------------------创建存储过程---------------------
1create procedure InsertPro
2@StuID int,
3@StuName varchar(10),
4@StuAddress varchar(20)
5as
6insert into 学生基本信息表 values(@StuID,@StuName,@StuAddress)
7
8-----------调用存储过程---------------
9exec InsertPro 5,'555','555'
--------------在Java中调用--------------------
1import java.sql.*;
2
3public 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 // 创建存储过程的对象
11 CallableStatement c = conn.prepareCall("{call InsertPro(?,?,?)}");
12 c.setInt(1, 6);
13 c.setString(2, "Liu");
14 c.setString(3, "wuhan");
15 c.execute();
16 c = conn.prepareCall("{call selePro}");
17 ResultSet rs = c.executeQuery();
18 while (rs.next()) {
19 String stuid = rs.getString("StuID");
20 String name = rs.getString("StuName");
21 String address = rs.getString("StuAddress");
22 System.out.println(stuid + " " + name + " " + address);
23 }
24 c.close();
25 }
26}
posted on 2009-02-19 10:06
飞翔天使 阅读(209)
评论(0) 编辑 收藏 所属分类:
java