Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: java & results sets
i'm not sure about the behavior you're seeing, maybe it has to do with
casting each attribute of the struct to a String and how the oracle
jdbc handles that. for me it works like this ..
(uses getArray() instead of getting resultset, and uses Datum.stringValue() instead of casting)
...
array1 = (ARRAY)((OracleCallableStatement)cstmt).getArray(1); Object[] vals = (Object[]) array1.getArray(); for (int i = 0; i < vals.length; i++) { oracle.sql.STRUCT theStruct = (oracle.sql.STRUCT) vals[i]; Datum[] attrs = theStruct.getOracleAttributes(); System.out.println(attrs[0].stringValue() + "," + attrs[1].stringValue()); }
...
HTH?
E_at_E.COM (steve) wrote in message news:<1f3kh7b.oznf6j1c0eqwwN%E_at_E.COM>...
> Hi,
> I have the following code, to validate a user
>
> that calls an oracle server side proc.
> the driver is oracle 8.1.5 thin, the database is 8i 8.1.5.
>
>
> the program compiles and runs, but the damned result set(myValues[0])
> is returning a string of values as follows
> "0x4152333930544B504C4E","0x74657374","0x31323334","0x73686974"
>
> which is actually the HEX representation of the strings
> ie
> 0x31323334 =1234
>
> the data contained is correct , but it is a hex string!! of the values i
> want.
> how can I correct the code or is it a bug
>
>
>
>
> public static String[] Validate_user(String User,String Password){
> String Magic_key="";
> String [] Ret_results=new String[]{"-1","","",""};
> ResultSet rset =null;
> ARRAY array1;
> Connection conn;
> OracleCallableStatement cstmt=null;
>
> // Create a statement
> // Execute the statement and query
> try
> {
> // Call the function which returns a nested table
>
> String The_qry="{ ? = call oracle.external_user.valid_usr("+
> "'"+User.trim()+
> "','"+Password.trim()+
> "','"+String.valueOf(SerialversionUID).trim()+
> "')}";
>
>
> cstmt=(OracleCallableStatement)SQL_functions.dbconn.prepareCall(The_qry)
> ;
>
>
> cstmt.registerOutParameter(1,OracleTypes.ARRAY,"ORACLE.RETURN_VARCHAR2_0
> 4");
> cstmt.execute();
>
> // Get the return value and covert it into a JDBC ResultSet
> array1 =
> (ARRAY)((OracleCallableStatement)cstmt).getOracleObject(1);
> rset=array1.getResultSet();
>
> // Loop through ResultSet rows
> while(rset.next()){
> // Get the object that is in the address_list ( SQL TYPE
> "ADDRESS" )
> // 1st column is the row index
> // 2nd column is the actual object
>
> oracle.sql.STRUCT obj= (oracle.sql.STRUCT)rset.getObject(2);
>
> // Get the column attributes for the object
>
> Object myValues[] = (Object[])obj.getAttributes();
>
>
> // Object myValues=obj.getAttributes();
> // get each of the object columns
> // It is the programmers responsibility to know specifically
> // what these types are. In this case they are all strings.
> //0x4152333930544B504C4E,0x74657374,0x31323334,0x73686974
> Ret_results[0]=(String)myValues[0];
> Ret_results[1]=(String)myValues[1];
> Ret_results[2]=(String)myValues[2];
> Ret_results[3]=(String)myValues[3];
>
>
> System.out.println(Ret_results[0]+","+Ret_results[1]+","+Ret_results[2]+
> ","+Ret_results[3]);
> // the above returns
> //0x4152333930544B504C4E,0x74657374,0x31323334,0x73686974 to the system
> screen.
> }
> }
>
> catch (Exception e)
> {
>
> Error_funcs.handleError(e);
> }
> return Ret_results;
> }
Received on Wed Nov 28 2001 - 16:44:20 CST
![]() |
![]() |