java

位置:IT落伍者 >> java >> 浏览文章

用java从oracle取数


发布日期:2022年03月21日
 
用java从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();

}

}

               

上一篇:OracleBerkeley数据库Java版

下一篇:servlet实现从oracle数据库的blob字段中读出文件并显示