File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Oracle Function returns ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Oracle Function returns ?" Watch "Oracle Function returns ?" New topic
Author

Oracle Function returns ?

Luis Felipe Bacca Arango
Greenhorn

Joined: May 26, 2003
Posts: 27
Hi, i have a problem with a function call from java.

I post here what i done, please help me.

//Create a type named arreglo
CREATE OR REPLACE TYPE ARREGLO IS VARRAY(28) OF VARCHAR2(50)

//Create a function that return an "arreglo" data type
CREATE OR REPLACE FUNCTION OBTIENEENTIDADES RETURN ARREGLO AS

datos ARREGLO := ARREGLO();
CURSOR c_datos is SELECT ENTIDAD_NOMBRE FROM A_ENTIDAD;

BEGIN

FOR cont IN c_datos LOOP
datos.extend;
datos(datos.count) := cont.ENTIDAD_NOMBRE;
END LOOP;

return datos;
END;

//Java code

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc racle:thin:@197.0.0.245:1521:ASOFHEIN","SIAFDES","Q1E3T5");
OracleCallableStatement ocs = (OracleCallableStatement)con.prepareCall("{ ? = call OBTIENEENTIDADES}");
ocs.registerOutParameter(1, OracleTypes.ARRAY, "ARREGLO");
ocs.executeUpdate();
ARRAY sA = ocs.getARRAY(1);
String [] valores = (String[])sA.getArray();
for(int i=0; i<valores.length; i++){
System.out.println(valores[i]);
}

That code return an array of 28 positions but all the data is '???',

what is wrong with my code ?? Please help me
[ February 25, 2005: Message edited by: Bear Bibeault ]

Luis Felipe.<br /> <br />SCJP, SCWCD.
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Did you try calling the getArray() method instead of getARRAY()?

Looks like it works the same, but returns java.sql.Array instead of oracle's ARRAY.

Array array = proc.getArray( 3 );

String[] timePeriods = (String[]) array.getArray();

I haven't used oracles ARRAY, but am interested.
Luis Felipe Bacca Arango
Greenhorn

Joined: May 26, 2003
Posts: 27
Hi Carol,

I already tried but the result its the same.

An array with '???' in all the positions.

Thanks
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

Luis Felipe,
My guess is that it is an internationalization (I18N) issue. Oracle do have special JARs to handle such issues. I can't be more specific because I have no experience in these matters.

The question marks ("?") probably mean that your java code cannot correctly display the Spanish characters you retrieved from your database.

If you haven't already done so, I suggest reading the Oracle "Globalization Support Guide" and check the OTN Web site for details on the relevant, required JAR files.

Good Luck,
Avi.
Luis Felipe Bacca Arango
Greenhorn

Joined: May 26, 2003
Posts: 27
Hi Avi, Thanks for your reply.

I will going to read the "Globalization Support Guide" looking for solutions to my problem.

Regards,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Oracle Function returns ?