Chinaunix首页 | 论坛 | 博客
  • 博客访问: 211132
  • 博文数量: 38
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 410
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-09 12:32
文章分类

全部博文(38)

文章存档

2011年(1)

2008年(12)

2007年(25)

我的朋友

分类: Java

2008-06-01 18:50:21

1. 建表及创建存储过程

conn scott/tiger

create table student(
    id number(15) primary key,
    name nvarchar(50) not null
);

create or replace procedure get_name(student_id in number, student_name out varchar)
is
begin
    select name into student_name from student where id = student_id;
end;

commit;


2. Java代码

package com.dlut.zxf.test;

import java.sql.*;

public class Test {
    public static void main(String[] args) {
        String classDriver = "oracle.jdbc.driver.OracleDriver";
        String dbURL = "jdbc:oracle:thin:@localhost:1521:xe";
        String user = "scott";
        String password = "tiger";
        
        Connection conn = null;        
        CallableStatement state = null;        

        try {
            Class.forName(classDriver);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        try {
            conn = DriverManager.getConnection(dbURL, user, password);
            state = conn.prepareCall("{call scott.get_name(?, ?)}");
            state.setString(1, "200592338");
            state.registerOutParameter(2, Types.VARCHAR);
            state.execute();
            System.out.println(state.getString(2));
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

阅读(1518) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~