创建存储过程的脚本,
使用sqlserver2000 中的pubs 数据库中的 jobs表为例.
| create procedure showAll as select * from jobs create procedure obtainJob_desc
|
用来获得连接的函数
| public Connection getConnection()...{ Connection con = null; try ...{ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); con = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;databasename=pubs","sa",""); } catch (Exception e) ...{ e.printStackTrace(); } return con ; } |
1,调用得到结果集的存储过程
| public void getResultSet()...{ //获得连接 Connection con = this.getConnection(); try ...{ //showAll为存储过程名 java.sql.CallableStatement cstm = con.prepareCall("{call showAll }"); ResultSet rs = cstm.executeQuery(); while(rs.next())...{ //这里写逻辑代码。 System.out.println(rs.getString(1)); } rs.close(); con.close(); } catch (SQLException e) ...{ // TODO Auto-generated catch block e.printStackTrace(); } } |
2,调用带有 输入 ,输出 参数的存储过程。
| public void getOutParameter(int inParam)...{ String outParam; Connection con = this.getConnection(); try ...{ //得到输出参数。 } catch (SQLException e) ...{ } |
3,调用带返回值的存储过程。
| public void getReturn()...{ int ret; Connection con = this.getConnection(); try ...{ CallableStatement cstm = con.prepareCall("{?=call obtainReturn()}"); cstm.registerOutParameter(1, Types.INTEGER); cstm.execute(); System.out.println(ret); } catch (SQLException e) ...{ } |
相关专题
- 电脑配置手册 (8545篇文章)
- 服务器配置专栏 (11126篇文章)
- Eclipse应用技术 (521篇文章)
- Wlan组网----家庭专题 (4270篇文章)
- Eclipse 入门及环境配置 (71篇文章)
- Eclipse 开发技术 (134篇文章)
- 在Eclipse中配置Struts2项目 (386次浏览)
- 史上最简单的struts+spring+hibernate配置实 (249次浏览)
- 在Spring中使用JTA事务管理 (231次浏览)
- 玩玩Spring之struts+hibernate+spring添删改 (156次浏览)
- 使用Spring MVC表单标签 (154次浏览)
- 在Spring中使用Quartz进行任务调度 (154次浏览)
- 使用myeclipse集成struts,hibernate,spring (142次浏览)
- 详细讲解在Spring中进行集成测试 (126次浏览)
- Java远程通讯可选技术及原理 (100次浏览)
- 使用Acegi进行身份认证(之一) (85次浏览)



