Advertisement
Guest User

Untitled

a guest
Feb 4th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. import java.sql.*;
  2. import java.io.*;
  3. import org.junit.Test;
  4. import static org.junit.Assert.*;
  5. import java.util.Arrays;
  6.  
  7. /* NOTE: custom_type type is created with:
  8. CREATE OR REPLACE TYPE public.custom_type AS OBJECT
  9. (
  10.    alpha varchar2(30), beta varchar2(20)
  11. );
  12. */
  13.  
  14. public class test
  15. {
  16.                 public static void main(String[] args)
  17.                 {
  18. try {
  19.                                                 //Class.forName("com.edb.Driver");
  20.                                                 Class.forName("org.postgresql.Driver");
  21. Connection conn = DriverManager.getConnection("jdbc:postgresql://192.168.59.103:22222/richyen_test", "enterprisedb","edb");
  22. //Connection conn = DriverManager.getConnection("jdbc:edb://192.168.59.103:22222/richyen_test", "enterprisedb","edb");
  23. String[] attributes1 = {"ABC123", "123ABC"};
  24. String[] attributes2 = {"456DEF", "XYZ123"};
  25. Struct agentIdStruct1 = conn.createStruct("custom_type", attributes1);
  26. Struct agentIdStruct2 = conn.createStruct("custom_type", attributes2);
  27. Struct[] elements = {agentIdStruct1, agentIdStruct2};
  28. Array agentIdArray = conn.createArrayOf("custom_type", elements);
  29. Object[] z = (Object[]) agentIdArray.getArray();
  30. for (int i = 0; i < z.length; i++) {
  31.   System.out.println( i + " " + z[i].getAttributes() + " " + elements[i]);
  32. }
  33. }
  34. catch(Exception err)
  35. {
  36. System.out.println("An error has occurred.");
  37. System.out.println("See full details below.");
  38. err.printStackTrace();
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement