熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Oracle >> 正文

用java從oracle取數

2022-06-13   來源: Oracle 

  /*
drop table varray_table;
drop type num_varray;

  CREATE TYPE num_varray AS VARRAY() OF VARCHAR()
/
CREATE TABLE varray_table (col num_varray);
INSERT INTO varray_table VALUES (num_varray(你好 abc));

  select * from varray_table;

  */

  import javasql*;
import javamath*;
import oraclejdbcdriver*;
import oraclesql*;

  class Array
{

  public static void main(String args[]) throws Exception
{
  int oracleId = CharacterSetZHSGBK_CHARSET;
  CharacterSet dbCharset = CharacterSetmake(oracleId);

  DriverManagerregisterDriver
                (new oraclejdbcdriverOracleDriver());

  Connection conn =
      DriverManagergetConnection
                       (jdbc:oracle:thin:@::db
                        mytest
                        mytest);

  Statement stmt = conncreateStatement();

  ResultSet rs = stmtexecuteQuery(SELECT * FROM varray_table);

  while (rsnext()) {
    ARRAY my_array = ((OracleResultSet)rs)getARRAY();

  // return the SQL type names integer codes
    // and lengths of the columns
    Systemoutprintln (Array is of type + my_arraygetSQLTypeName());
    Systemoutprintln (Array element is of typecode + my_arraygetBaseType());
    Systemoutprintln (Array is of length + my_arraylength());

  // get Array elements
    String[] values = (String[]) my_arraygetArray();
    for (int i = ; i < valueslength; i++)
    {
       oraclesqlCHAR out_value = new oraclesqlCHAR(values[i] dbCharset);
       Systemoutprintln(>> index + i + = + out_value);
    }

  }

  rsclose();
  stmtclose();
  connclose();
  }
}


From:http://tw.wingwit.com/Article/program/Oracle/201311/17881.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.