Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import java.io.*;
- import org.junit.Test;
- import static org.junit.Assert.*;
- import java.util.Arrays;
- /* NOTE: custom_type type is created with:
- CREATE OR REPLACE TYPE public.custom_type AS OBJECT
- (
- alpha varchar2(30), beta varchar2(20)
- );
- */
- public class test
- {
- public static void main(String[] args)
- {
- try {
- //Class.forName("com.edb.Driver");
- Class.forName("org.postgresql.Driver");
- Connection conn = DriverManager.getConnection("jdbc:postgresql://192.168.59.103:22222/richyen_test", "enterprisedb","edb");
- //Connection conn = DriverManager.getConnection("jdbc:edb://192.168.59.103:22222/richyen_test", "enterprisedb","edb");
- String[] attributes1 = {"ABC123", "123ABC"};
- String[] attributes2 = {"456DEF", "XYZ123"};
- Struct agentIdStruct1 = conn.createStruct("custom_type", attributes1);
- Struct agentIdStruct2 = conn.createStruct("custom_type", attributes2);
- Struct[] elements = {agentIdStruct1, agentIdStruct2};
- Array agentIdArray = conn.createArrayOf("custom_type", elements);
- Object[] z = (Object[]) agentIdArray.getArray();
- for (int i = 0; i < z.length; i++) {
- System.out.println( i + " " + z[i].getAttributes() + " " + elements[i]);
- }
- }
- catch(Exception err)
- {
- System.out.println("An error has occurred.");
- System.out.println("See full details below.");
- err.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement