Guest User

Untitled

a guest
May 31st, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. FUNCTION PROCESS_FILE_INTERNAL
  2. (
  3. i_Filename VARCHAR2,
  4. i_EventType NUMBER
  5. )
  6. RETURN PROCESSEXCELFILEARGS
  7.  
  8. OracleCallableStatement cstmt = null;
  9. try{
  10. OracleDriver ora = new OracleDriver();
  11. DriverManager.registerDriver(ora);
  12.  
  13. Connection connection = ora.defaultConnection();
  14. String call = "{ ? = call NEUTRINO_META.PKG_EXCEL.PROCESS_FILE_INTERNAL(?, ?) }";
  15. cstmt = (OracleCallableStatement)connection.prepareCall(call);
  16. cstmt.setQueryTimeout(1800);
  17. cstmt.registerOutParameter(1, OracleTypes.OTHER, "NEUTRINO_META.PROCESSEXCELFILEARGS");
  18. cstmt.setString(2, filename);
  19. cstmt.setDouble(3, eventType);
  20. cstmt.execute();
  21.  
  22. OracleObjects.ProcessExcelFileArgsobj = (OracleObjects.ProcessExcelFileArgs)cstmt.getObject(1);
  23. connection.commit();
  24.  
  25.  
  26. }
  27. catch (SQLException e){
  28. WriteEventToDb(e.getMessage());
  29. }
  30. finally{
  31. if (cstmt != null){
  32. cstmt.close();
  33. }
  34. }
  35.  
  36. create or replace
  37. TYPE PROCESSEXCELFILEARGS FORCE AS OBJECT
  38. (
  39. FullFilePath VARCHAR2(700),
  40. Filename VARCHAR2(200),
  41. Graph TYPEGRAPHDATA
  42. )
  43.  
  44. create type type_dummy is object (
  45. id int,
  46. name varchar2(10)
  47. )
  48. /
  49.  
  50. create or replace function get_type_dummy
  51. return type_dummy
  52. is
  53. begin
  54. return type_dummy(1,'ABCDe');
  55. end;
  56. /
  57.  
  58. class TypeDummy {
  59. public Long id;
  60. public String name;
  61. }
  62.  
  63.  
  64.  
  65. try {
  66. DriverManager.registerDriver ( new oracle.jdbc.driver.OracleDriver());
  67. Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@ods.fors.ru:1521:test","odh","odh");
  68. OracleCallableStatement cstmt = (OracleCallableStatement)conn.prepareCall("{ ? = call get_type_dummy }"); ;
  69. cstmt.registerOutParameter(1, OracleTypes.JAVA_STRUCT, "TYPE_DUMMY");
  70. cstmt.execute();
  71. oracle.sql.STRUCT td = (oracle.sql.STRUCT)cstmt.getObject(1);
  72. Object[] x = td.getAttributes();
  73. TypeDummy ntd = new TypeDummy();
  74. ntd.id = ((BigDecimal)x[0]).longValue();
  75. ntd.name = (String)x[1];
  76. System.out.println(ntd.id);
  77. System.out.println(ntd.name);
  78. cstmt.close();
  79. }
  80. ...
  81.  
  82. 1
  83. ABCDe
  84.  
  85. try{
  86. Map rtn = connection.getTypeMap();
  87. rtn.put("NEUTRINO_META.PROCESSEXCELFILEARGS", Class.forName("OracleObjects.ProcessExcelFileArgs"));
  88. String call = "{ ? = call NEUTRINO_META.PKG_EXCEL.PROCESS_FILE_INTERNAL(?, ?) }";
  89. cstmt = (OracleCallableStatement)connection.prepareCall(call);
  90. cstmt.setQueryTimeout(1800);
  91. cstmt.registerOutParameter(1, OracleTypes.STRUCT, "NEUTRINO_META.PROCESSEXCELFILEARGS");
  92. cstmt.setString(2, filename);
  93. cstmt.setDouble(3, eventType);
  94. cstmt.execute();
  95.  
  96. ProcessExcelFileArgs args = (ProcessExcelFileArgs)cstmt.getObject(1, rtn);
  97.  
  98. }
  99. catch (SQLException e){
  100. WriteEventToDb(e.getMessage());
  101. }
  102. finally{
  103. if (cstmt != null){
  104. cstmt.close();
  105. }
  106. }
Add Comment
Please, Sign In to add comment