Results 1 to 2 of 2
  1. #1
    Aispam is offline Member
    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0

    Default Printing out results of a table in case of object-relational structure (ORACLE)

    I have made a table with this structure:

    Java Code:
    CREATE OR REPLACE TYPE Boat AS OBJECT(
    Name varchar2(30),
    Ident number,
    );
    
    CREATE OR REPLACE TYPE Type_boats AS TABLE OF Boat;
    
    CREATE TABLE HOUSE(
    Name varchar2(40),
    MB Type_boats)
    NESTED TABLE MB store as P_Boat;
    
    INSERT INTO House VALUES ('Name',Type_boats(Boat('Boat1', 1)));
    I am using java to print out all the results by calling a procedure.
    Java Code:
     
    CREATE OR REPLACE package House_boats
    PROCEDURE add(everything works here)
    PROCEDURE results_view;
    END House_boats;
    
    CREATE OR REPLACE Package.body House_boats AS
    PROCEDURE add(everything works here) AS LANGUAGE JAVA
    Name House_boats.add(...)
    
    PROCEDURE results_view AS LANGUAGE JAVA
    Name House_boats.resuts_view();
    END House_boats;
    However, I am not able to get Results.view working in case of object-relation table. This is how I do it in the situation of relational table.

    Java Code:
    CALL House_boats.results_view();

    House_boats.java file which is loaded using LOADJAVA:

    Java Code:
    import java.sql.*;
    import java io.*;
    
    public class House_boats {
    
    public static void results_view () 
       throws SQLException 
       { String sql = 
       "SELECT * from House";
       try { Connection conn = DriverManager.getConnection 
    ("jdbc:default:connection:");
       PreparedStatement pstmt = conn.prepareStatement(sql);
       ResultSet rset = pstmt.executeQuery();
      printResults(rset);
      rset.close();
      pstmt.close(); 
       } 
       catch (SQLException e) {System.err.println(e.getMessage());
       }  
      }
    
    static void printResults (ResultSet rset) 
       throws SQLException { String buffer = "";
       try { ResultSetMetaData meta = rset.getMetaData();
       int cols = meta.getColumnCount(), rows = 0;
       for (int i = 1; i <= cols; i++) 
       {
       int size = meta.getPrecision(i);
       String label = meta.getColumnLabel(i);
       if (label.length() > size) size = label.length();
       while (label.length() < size) label += " ";
      buffer = buffer + label + " "; }
      buffer = buffer + "\n";
       while (rset.next()) {
      rows++;
       for (int i = 1; i <= cols; i++) {
       int size = meta.getPrecision(i);
       String label = meta.getColumnLabel(i);
       String value = rset.getString(i);
       if (label.length() > size) size = label.length();
       while (value.length() < size) value += " ";
      buffer = buffer + value + " ";  }
      buffer = buffer + "\n";   }
       if (rows == 0) buffer = "No data found!\n";
       System.out.println(buffer); } 
       catch (SQLException e) {System.err.println(e.getMessage());}  }
    }
    How do I print out the results correctly in my case of situation?
    Thank you in advance

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,008
    Rep Power
    20

    Default Re: Printing out results of a table in case of object-relational structure (ORACLE)

    You haven't actually said what your problem is.
    What are you seeing?
    What should you be seeing?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 1
    Last Post: 11-17-2011, 06:59 PM
  2. Printing results from another class
    By TheCase in forum New To Java
    Replies: 1
    Last Post: 10-30-2011, 05:22 PM
  3. Replies: 5
    Last Post: 12-15-2010, 02:22 AM
  4. Replies: 1
    Last Post: 10-18-2010, 07:14 AM
  5. Printing Tree Structure using Swings
    By pradeep1_mca@yahoo.com in forum AWT / Swing
    Replies: 5
    Last Post: 08-30-2008, 01:54 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •