Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2119829
  • 博文数量: 1647
  • 博客积分: 80000
  • 博客等级: 元帅
  • 技术积分: 9980
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 15:15
文章分类

全部博文(1647)

文章存档

2011年(1)

2008年(1646)

我的朋友

分类:

2008-10-28 18:10:13

/*
drop table varray_table;
drop type num_varray;

CREATE TYPE num_varray AS VARRAY(10) OF VARCHAR2(12)
/
CREATE TABLE varray_table (col1 num_varray);
INSERT INTO varray_table VALUES (num_varray('你好', 'abc'));

select * from varray_table;

*/

import java.sql.*;
import java.math.*;
import oracle.jdbc.driver.*;
import oracle.sql.*;

class Array1
{

public static void main(String args[]) throws Exception
{
  int oracleId = CharacterSet.ZHS16GBK_CHARSET;
  CharacterSet dbCharset = CharacterSet.make(oracleId);

  DriverManager.registerDriver
                (new oracle.jdbc.driver.Driver());

  Connection conn =
      DriverManager.getConnection
                       ("jdbc:oracle:thin:@10.9.200.58:1521:db01",
                        "mytest",
                        "mytest");

  Statement stmt = conn.createStatement();

  ResultSet rs = stmt.executeQuery("SELECT * FROM varray_table");

  while (rs.next()) {
    ARRAY my_array = ((ResultSet)rs).getARRAY(1);

    // return the SQL type names, integer codes,
    // and lengths of the columns
    System.out.println ("Array is of type " + my_array.getSQLTypeName());
    System.out.println ("Array element is of typecode " + my_array.getBaseType());
    System.out.println ("Array is of length " + my_array.length());

    // get Array elements
    String[] values = (String[]) my_array.getArray();
    for (int i = 0; i < values.length; i++)
    {
       oracle.sql.CHAR out_value = new oracle.sql.CHAR(values[i], dbCharset);
       System.out.println(">> index " + i + " = " + out_value);
    }


  }

  rs.close();
  stmt.close();
  conn.close();
  }
}

【责编:landss】

--------------------next---------------------

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