用java从oracle取数_Oracle数据库_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

用java从oracle取数

作者:黑客防线网安Oracle维护基地 来源:黑客防线网安Oracle维护基地 浏览次数:0

黑客防线网安网讯:/*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...

/*
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.OracleDriver());   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 = ((OracleResultSet)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();
  }
}

    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-12180-1.html
网站维护教程更新时间:2012-03-23 00:34:29  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer