随笔 - 147  文章 - 71  trackbacks - 0
<2009年2月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
1234567

常用链接

留言簿(1)

随笔分类(146)

随笔档案(147)

文章分类(28)

文章档案(28)

喜欢的Blog

搜索

  •  

最新评论

阅读排行榜

评论排行榜

---------------------创建存储过程---------------------
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(16);
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 飞翔天使 阅读(201) 评论(0)  编辑  收藏 所属分类: java

只有注册用户登录后才能发表评论。


网站导航: