This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Any replacement for ArrayDescriptor? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Any replacement for ArrayDescriptor?" Watch "Any replacement for ArrayDescriptor?" New topic
Author

Any replacement for ArrayDescriptor?

xing wogong
Greenhorn

Joined: Jul 25, 2002
Posts: 10
Hi, I am using stored procedure which received the java array I passed like this:

public class ArrayDemo

public static void passArray() throws SQLException
{
Connection conn =
new OracleDriver().defaultConnection();

int intArray[] = { 1,2,3,4,5,6 };

ArrayDescriptor descriptor =
ArrayDescriptor.createDescriptor( "NUM_ARRAY", conn );

ARRAY array_to_pass =
new ARRAY( descriptor, conn, intArray );
OraclePreparedStatement ps =
(OraclePreparedStatement)conn.prepareStatement
( "begin give_me_an_array(:x); end;" );
ps.setARRAY( 1, array_to_pass );
ps.execute();
}
Somehow, my company does not allow us to use any oracle extension on JDBC, and we only can use API that used in standard JDBC. But in standard JDBC, I can not find a equivalent object as oracle's ArrayDescriptor, and there is not constructor for java.sql.Array, thus I do not know how to construct an Array object in Java side.

What should I do then? Is it impossible for me to avoid oracle's extention?

Thanks
Wogong
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

"xingwogong",
We're pleased to have you here with us in the JDBC forum, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

Xing,
I think databases handle arrays in different ways. Just like BLOB/CLOB, there is no vendor netural class. In the case of BLOB/CLOB, there are alternative ways of setting the value (like a byte array or binary stream.)

The lack of response to this questions also indicates that nobody has done this for arrays. From the JavaDoc, it looks like the implementation of Array is very database specific.
Devendra Thomare
Greenhorn

Joined: Dec 13, 2008
Posts: 15
Xing,

I am facing same problem as you ,


could you please let me know if you have got answer for mentioned problem ?

Thanks ,
Devendra


SCJP 88% SCWCD 88%SCBCD 88%
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1121

Wogong,
You said:

there is not constructor for java.sql.Array

"java.sql.Array" is an interface, not a class, and therefore has no constructor.
Obviously every JDBC driver is going to implement this interface differently.
Hence, as Jeanne said, there is no database-independent way to pass an array to a stored procedure.
As far as I can see, you simply need to find a different way of passing an array of values to your stored procedure.

Good Luck,
Avi.
Devendra Thomare
Greenhorn

Joined: Dec 13, 2008
Posts: 15
Thanks Avi ....

I tried another way I created one custom class which implements java.sql.SQLData .

In this class we will have one property e.g (String[] which we wanted to give as array)

and then create instance of this class and set this object as cstmt.setObject()

but it didnt work ...


public class UserApplicationSQL implements SQLData {

/** Creates a new instance of UserApplicationSQL */

private static final String typeName="ECPIXDBA.TBL_PARA";

public String[] array;
public UserApplicationSQL(String[] array) {
this.array=array;
System.out.println("in construcotr"+this.array.length);
}

public String getSQLTypeName() throws SQLException {
return typeName;
}

public void readSQL(SQLInput stream, String typeName) throws SQLException {

}

public void writeSQL(SQLOutput stream) throws SQLException {

for(int i=0;i<array.length;i++){
stream.writeString(array[i]);
}

}

}

AND in my caller class
UserApplicationSQL usa=new UserApplicationSQL ()

and passing this object to setObject

please let me know if i am doing any mistake in this

any way now i had to split my stored procedure and i am calling my query by looping values in array ....
 
wood burning stoves
 
subject: Any replacement for ArrayDescriptor?
 
Similar Threads
any replacement for ArrayDescriptor
getting underlying oracle connection from Poolable connection
Any Replacement of ArrayDescriptor?
Passing multiple values to a stored procedure
Passing array input in procedure - thin driver