【问题标题】:Why string is not printing correctly?为什么字符串打印不正确?
【发布时间】:2012-09-13 19:42:48
【问题描述】:

我在 oracle 中创建了一个用户类型

create or replace type my_friend_list 
is
table of 
varchar2(100);

现在我编写了一个具有如下输出参数的程序:

  PROCEDURE friends_diff_prc
  (
   my_name IN VARCHAR2,
   friend_i   IN my_friend_list ,
   good_friend_o   OUT my_friend_list ,
   best_friend_o   OUT my_friend_list ,
   isSuccess         OUT NUMBER 
  );

我在SQLDeveloper 上运行它并且运行正常。

它给我列出了我的好朋友和最好的朋友。

但是当我通过扩展 StoredProcedure 的 JAVA 类调用它时。

best_friend 列表即将到来,但 good_friend 列表正在打印

Ljava.lang.Object;@24342434, 
Ljava.lang.Object;@243a243a,
Ljava.lang.Object;@24402440,
Ljava.lang.Object;@24462446

我获取这个输出数组列表的 java 代码是这样的:

List<String> goodfriends = Arrays.asList((String[]) results.get("good_friend_o");
List<String> bestfriends = Arrays.asList((String[]) results.get("best_friend_o");

为什么它没有为 good_friends 提供正确的结果?

提前致谢。

【问题讨论】:

  • Ljava.lang.Object;@24462446 表示您正在尝试打印 Object[] 数组。您能否尝试使用 for(Object o : (Object[]) goodFriend) {System.out.println(o);} 遍历 good_friend 实例并使用结果编辑您的问题?
  • @sp00M 我不明白为什么它为最好的朋友正确打印
  • 我也不知道,但如果你按照我告诉你的那样尝试打印,也许我们会找到。

标签: java sql oracle spring stored-procedures


【解决方案1】:

您将答案作为字符串数组,然后存储在列表字符串中。您不能将 String[] 直接存储到字符串中。

你能发布用于获取和打印的 java 代码吗...

【讨论】:

    【解决方案2】:

    试试这个代码。这将打印字符串

    System.out.println("Printing goodfriends");
    for (Object object : goodfriends) {
        Object[] goodfriendsString = (Object[]) object;
        for (Object object2 : objLocationVO) {
        System.out.println(object2);            
         }
    }
    

    【讨论】:

    • 这不是一个解决方案,而是一个调试步骤。所以,它应该是一个评论而不是一个anwser。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-06
    • 2020-07-27
    • 2020-11-08
    • 2021-04-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多