Use Java from Oracle

xiaoxiao2021-03-06  67

This article illustrates how to get an array from Oracle with Java and resolve the characters display HEX garbled code / * 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 ('Hello', '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 > INDEX" i "=" out_value);

}

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

转载请注明原文地址:https://www.9cbs.com/read-89734.html

New Post(0)