I have troubles with getting my data to Java from Oracle DB. Instead of real value, only 3 question marks are returned from database.
First i created my type as follows:
create or replace TYPE varchar2_ntt AS VARRAY(5000) OF varchar2(200);
Then I wrote my sql:
SELECT del.stop_name AS direction,
del.departures
FROM
(SELECT mvv.STOP_NAME,
mvv.stop_id,
CAST( COLLECT(SUBSTR(departure_time,1,5)
ORDER BY departure_time) AS varchar2_ntt ) departures
FROM stop_times st,
MV_TRIP_V_SMER mvv,
trips t
LEFT JOIN calendar c
ON c.service_id= t.service_id,
routes r,
mv_rezimi_za_postajni_vr pvr
WHERE mvv.trip_id =st.trip_id
AND st.trip_id =t.TRIP_ID
AND r.route_id =t.route_id
AND pvr.service_id=c.service_id
AND pvr.workday=1
AND st.stop_id ='2206100000201'
GROUP BY mvv.STOP_NAME,
mvv.stop_id
) DEL
result for column departures in sql developer looks fine.
SHEMA.VARCHAR2_NTT('13:15','16:25','18:15','19:45')
In Java im trying to get the results:
while (rs.next()){
ARRAY departures_a =((OracleResultSet)rs).getARRAY("departures");
System.out.println ("Array is of type "+departures_a.getSQLTypeName());
System.out.println ("Array is of length "+departures_a.length());
String[] departures_arr = (String[]) departures_a.getArray();
for (int n=0; n<departures_arr.length; n++){
System.out.println("departure "+n+":"+ departures_arr[n]);
}
}
Console output:
Array is of type SHEMA.VARCHAR2_NTT
Array is of length 4
departure 0:???
departure 1:???
departure 2:???
departure 3:???
What im doing wrong? Why there are question marks instead of real values?
Might be a charset problem. Try to print the result you receive.
System.out.printf("departure %d: %s%n", i, Arrays.toString(departures[i].getBytes()));
Print also the typecode
System.out.println("Array element is of typecode " + departures_a.getBaseType());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.