Using Java to fetch numbers from Oracle

Source: Internet
Author: User
Oracle/*
drop table varray_table;
Drop type Num_varray;

CREATE TYPE Num_varray as Varray 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 < 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 ();
}
}





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.