oracle - Accessing XML using XQuery (within XQJ code) from a column in database table -
i have created following table in locally installed oracle database :-
create table "system"."warehouses" ( "warehouse_id" number not null enable, "warehouse_spec" clob, constraint "warehouses_pk" primary key ("warehouse_id");
it 4 rows primary keys 1,2,3 , 4.
now have written following java code access "warehouse_spec" column (which contains xml file every row) :-
import oracle.xml.xquery.xqjdb.oxqddatasource; import javax.xml.xquery.xqitemtype; import javax.xml.xquery.xqresultsequence; import javax.xml.xquery.xqconnection; import javax.xml.xquery.xqpreparedexpression; import javax.xml.namespace.qname; public class accessdata { public static void main(string argv[]) { try { oxqddatasource oxqds = new oxqddatasource(); oxqds.setproperty("driver", "jdbc:oracle:thin"); oxqds.setproperty("dbusername", "system"); oxqds.setproperty("dbpassword", "pwd"); oxqds.setproperty("dbserver", "localhost"); oxqds.setproperty("dbport", "1521"); oxqds.setproperty("servicename", "xe"); xqconnection conn = oxqds.getconnection(); xqitemtype itemtypeint = conn.createatomictype(xqitemtype.xqbasetype_int); xqpreparedexpression expr = conn.prepareexpression("declare variable $x xs:int external; $i in fn:collection('oradb:/mydb/warehouses') $i/row/warehouse_id < $x return $i/row/warehouse_spec/warehouse"); expr.bindint(new qname("x"), 3, itemtypeint); xqresultsequence xqseq = expr.executequery(); while (xqseq.next()) { system.out.println(1); system.out.println (xqseq.getitemasstring(null)); } } catch (exception e) { e.printstacktrace(); } } }
here, "mydb" database schema , "warehouses" table name.
the code should return 2 rows primary keys 1 , 2, instead, unable find table, , giving following error :-
javax.xml.xquery.xqexception: java.sql.sqlexception: ora-00942: table or view not exist @ oracle.xml.xquery.xqjimpl.oxqdsequence.next(oxqdsequence.java:421) @ example1.main(accessdata.java:33) caused by: java.lang.runtimeexception: java.sql.sqlexception: ora-00942: table or view not exist @ oracle.xml.xquery.xqjimpl.xqjdbinfrastructure.oxqdxdbconnexpr.prepare(oxqdxdbconnexpr.java:367) @ oracle.xml.xquery.xqjimpl.xqjdbinfrastructure.oxqdxdbconnexpr.access$000(oxqdxdbconnexpr.java:102) @ oracle.xml.xquery.xqjimpl.xqjdbinfrastructure.oxqdxdbconnexpr$xdbconniterator.restart(oxqdxdbconnexpr.java:808) @ oracle.xml.xquery.xqjimpl.xqjdbinfrastructure.oxqdxquerysequence.next(oxqdxquerysequence.java:127) @ oracle.xml.xquery.xqjimpl.oxqdsequence.next(oxqdsequence.java:386) ... 1 more caused by: java.sql.sqlexception: ora-00942: table or view not exist @ oracle.jdbc.driver.databaseerror.throwsqlexception(databaseerror.java:112) @ oracle.jdbc.driver.t4cttioer.processerror(t4cttioer.java:331) @ oracle.jdbc.driver.t4cttioer.processerror(t4cttioer.java:288) @ oracle.jdbc.driver.t4c8oall.receive(t4c8oall.java:745) @ oracle.jdbc.driver.t4cpreparedstatement.dooall8(t4cpreparedstatement.java:219) @ oracle.jdbc.driver.t4cpreparedstatement.executefordescribe(t4cpreparedstatement.java:813) @ oracle.jdbc.driver.oraclestatement.executemaybedescribe(oraclestatement.java:1049) @ oracle.jdbc.driver.t4cpreparedstatement.executemaybedescribe(t4cpreparedstatement.java:854) @ oracle.jdbc.driver.oraclestatement.doexecutewithtimeout(oraclestatement.java:1154) @ oracle.jdbc.driver.oraclepreparedstatement.executeinternal(oraclepreparedstatement.java:3370) @ oracle.jdbc.driver.oraclepreparedstatement.executequery(oraclepreparedstatement.java:3415) @ oracle.xml.xquery.xqjimpl.xqjdbinfrastructure.oxqdxdbconnexpr.prepare(oxqdxdbconnexpr.java:351) ... 5 more
am doing wrong here ?
Comments
Post a Comment