Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8292935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:39:14+00:00 2026-06-08T13:39:14+00:00

I have implemented java.sql.SQLData in order to bind UDT objects to prepared statements using

  • 0

I have implemented java.sql.SQLData in order to bind UDT objects to prepared statements using ojdbc6. Now, some of my UDT’s contain arrays. What I need to do now is this:

class MyType implements SQLData {
  public void writeSQL(SQLOutput stream) throws SQLException {
    Array array = //...
    stream.writeArray(array);
  }
}

In order to construct Oracle arrays, I need a JDBC Connection. Typically, this is done as such:

OracleConnection conn = // ...
Array array = conn.createARRAY("MY_ARRAY_TYPE", new Integer[] { 1, 2, 3 });

However, in that writeSQL(SQLOutput) method, I do not have a connection. Also, for reasons that are hard to explain in a concise question, I cannot maintain a connection reference in MyType. Can I somehow extract that connection from SQLOutput? I’d like to avoid using instable constructs like this:

// In ojdbc6, I have observed a private "conn" member in OracleSQLOutput:
Field field = stream.getClass().getDeclaredField("conn");
field.setAccessible(true);
OracleConnection conn = (OracleConnection) field.get(stream);

Any ideas? Alternatives?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T13:39:23+00:00Added an answer on June 8, 2026 at 1:39 pm

    Here’s what I did to workaround this issue. It’s not pretty, but it works.

    I added a method in my class implementing SQLData that receives a java.sql.Connection and setups the corresponding java.sql.ARRAY objects.

    Something like this:

    public class MyObject01 implements SQLData {
       private String value;
       private MyObject02[] details; // do note that details is a java array
       // ... also added getters and setters for these two properties
    
       private Array detailsArray;
    
       public void setupArrays(oracle.jdbc.OracleConnection oconn)
          throws SQLException
       {
           detailsArrays = oconn.createARRAY(MyObject02.ORACLE_OBJECT_ARRAY_NAME, getDetails());
           // MyObject02.ORACLE_OBJECT_ARRAY_NAME must be the name of the oracle "table of" type name
           // Also note that in Oracle you can't use JDBC's default createArray
           // since it's not supported. That's why you need to get a OracleConnection
           // instance here. 
       }       
    
       @Override
       public void writeSQL(Stream stream) throws SQLException {
           stream.writeString(getValue());
           stream.writeArray(detailsArray); // that's it
       }
    
       @Override
       public void readSQL(Stream stream) throws SQLException {
           setValue(stream.readString());
           Array array = stream.readArray();
           if (array != null) {
               setDetails((MyObject02[])array.getArray());
           }
       }
    

    That’s the first part.

    Then, BEFORE using that object in a procedure call, invoke setupArrays method on that object. Example:

    public class DB {
        public static String executeProc(Connection conn, MyObject01 obj)
            throws SQLException
        {
            CalllableStatement cs = conn.prepareCall(" { ? = call sch.proc(?) }");
            cs.registerOutParameter(1, Types.VARCHAR);
            obj.setupArrays((oracle.jdbc.Connection)conn);
            cs.setObject(2, obj, Types.STRUCT);
            cs.executeUpdate();
            String ret = cs.getString(1);
            cs.close();
            return ret;
        }
    }
    

    Of course, upon connection, you need to register your types properly:

    Connection conn = DriverManager.getConnection("jdbc:oracle://localhost:1521/XE", "scott", "tiger" );
    conn.getTypeMap().put(MyObject01.ORACLE_OBJECT_NAME, MyObject01.class);
    conn.getTypeMap().put(MyObject02.ORACLE_OBJECT_NAME, MyObject02.class);
    conn.getTypeMap().put(MyObject02.ORACLE_OBJECT_ARRAY_NAME, MyObject02[].class);
    

    Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using java.sql.SQLData interface to map my java objects to Oracle database types.
I have implemented PHP-Java bridge and it works. Now i thought of implementing the
We have implemented a general purpose deep copy mechanism using serialization. import java.io.*; public
I have a keyword implemented with Java and if keyword fails i need to
I have implemented a simple RSS reader in Java. I hit a URL and
I am currently writing a Java compiler and have implemented section 15.12.2.7. of the
My web application is written using jsp/javascripts. Backend Java. Have managed to implement the
I have a stand-alone java application that makes some database read/write business on a
Has anyone successfully implemented a Java based solution that uses Microsoft SQL Server 2005
Now I have a search textField implemented with KeyReleased event, which don't found/update jTable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.